diff --git a/CHANGES.md b/CHANGES.md index f989973a..5b456ad8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -46,6 +46,11 @@ * Add scene qualities WEB.h264 to SDTV, 720p.WEB.h264 to WEB DL 720p, and 1080p.WEB.h264 to WEB DL 1080p +### 0.11.8 (2016-03-16 12:50:00 UTC) + +* Fix ensures internal buffer of a downloaded file is written to disk + + ### 0.11.7 (2016-03-06 12:30:00 UTC) * Fix Torrenting provider diff --git a/sickbeard/databases/mainDB.py b/sickbeard/databases/mainDB.py index c9388933..88536b35 100644 --- a/sickbeard/databases/mainDB.py +++ b/sickbeard/databases/mainDB.py @@ -977,6 +977,18 @@ class Migrate41(db.SchemaUpgrade): return self.checkDBVersion() +# 4301 -> 10001 +class Migrate4301(db.SchemaUpgrade): + def execute(self): + db.backup_database('sickbeard.db', self.checkDBVersion()) + + logger.log(u'Dropping redundant column') + self.dropColumn('db_version', 'db_minor_version') + + self.setDBVersion(10001) + return self.checkDBVersion() + + # 5816 - 5818 -> 15 class MigrateUpstream(db.SchemaUpgrade): def execute(self): @@ -1046,4 +1058,4 @@ class AddTvShowTags(db.SchemaUpgrade): self.addColumn('tv_shows', 'tag', 'TEXT', 'Show List') self.setDBVersion(20003) - return self.checkDBVersion() \ No newline at end of file + return self.checkDBVersion() diff --git a/sickbeard/db.py b/sickbeard/db.py index f6a1be14..fcb4a3c7 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -28,6 +28,7 @@ import sickbeard from sickbeard import encodingKludge as ek from sickbeard import logger from sickbeard.exceptions import ex +import helpers db_lock = threading.Lock() @@ -48,8 +49,15 @@ def dbFilename(filename='sickbeard.db', suffix=None): class DBConnection(object): def __init__(self, filename='sickbeard.db', suffix=None, row_type=None): + + db_src = dbFilename(filename) + if not os.path.isfile(db_src): + db_alt = dbFilename('sickrage.db') + if os.path.isfile(db_alt): + helpers.copyFile(db_alt, db_src) + self.filename = filename - self.connection = sqlite3.connect(dbFilename(filename), 20) + self.connection = sqlite3.connect(db_src, 20) if row_type == 'dict': self.connection.row_factory = self._dict_factory @@ -67,6 +75,9 @@ class DBConnection(object): return 0 if result: + if self.hasColumn('db_version', 'db_minor_version'): + minor = self.select('SELECT db_minor_version FROM db_version') + return int(result[0]['db_version']) * 100 + int(minor[0]['db_minor_version']) return int(result[0]['db_version']) else: return 0 @@ -411,6 +422,10 @@ def MigrationCode(myDB): 40: sickbeard.mainDB.BumpDatabaseVersion, 41: sickbeard.mainDB.Migrate41, 42: sickbeard.mainDB.Migrate41, + 43: sickbeard.mainDB.Migrate41, + 44: sickbeard.mainDB.Migrate41, + + 4301: sickbeard.mainDB.Migrate4301, 5816: sickbeard.mainDB.MigrateUpstream, 5817: sickbeard.mainDB.MigrateUpstream, @@ -457,4 +472,4 @@ def backup_database(filename, version): if not sickbeard.helpers.backupVersionedFile(dbFilename(filename), version): logger.log_error_and_exit(u'Database backup failed, abort upgrading database') else: - logger.log(u'Proceeding with upgrade') \ No newline at end of file + logger.log(u'Proceeding with upgrade') diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index f9a64e5f..6eaea47e 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1257,6 +1257,7 @@ def download_file(url, filename, session=None): if chunk: fp.write(chunk) fp.flush() + os.fsync(fp.fileno()) chmodAsParent(filename) except requests.exceptions.HTTPError as e: