Skip to content

Commit

Permalink
fixup! Implement upgrade procedure to migrate to the new torrent store.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elric Milon committed Jan 27, 2015
1 parent 9755c59 commit 7855a48
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Tribler/Core/Upgrade/db_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ class DBUpgrader(object):
structure from Tribler version 6.3 to 6.4.
"""

def __init__(self, session, db, status_update_func=None):
def __init__(self, session, db, torrent_store, status_update_func=None):
self._logger = logging.getLogger(self.__class__.__name__)
self.session = session
self.db = db
self.status_update_func = status_update_func if status_update_func else lambda _: None
self.torrent_store = torrent_store

self.failed = True
self.torrent_collecting_dir = self.session.get_torrent_collecting_dir()
Expand Down Expand Up @@ -357,13 +358,10 @@ def reimport_torrents(self):
torrent_db_handler.misc_db.initialize()
torrent_db_handler.category = Category.getInstance()

self.status_update_func("Opening torrent store...")
torrent_store = TorrentStore(self.session.get_torrent_store_dir())

# TODO(emilon): It would be nice to drop the corrupted torrent data from the store as a bonus.
self.status_update_func("Registering recovered torrents...")
try:
for infoshash_str, torrent_data in torrent_store.itervalues():
for infoshash_str, torrent_data in self.torrent_store.itervalues():
self.status_update_func("> %s" % infoshash_str)
torrentdef = TorrentDef.load_from_memory(torrent_data)
if torrentdef.is_finalized():
Expand All @@ -375,4 +373,4 @@ def reimport_torrents(self):
torrent_db_handler.close()
Category.delInstance()
self.db.commit_now()
return torrent_store.close()
return self.torrent_store.flush()

0 comments on commit 7855a48

Please sign in to comment.