diff options
author | Andrew Resch <andrewresch@gmail.com> | 2009-01-14 02:45:11 +0000 |
---|---|---|
committer | Andrew Resch <andrewresch@gmail.com> | 2009-01-14 02:45:11 +0000 |
commit | 8bd576f6364738bc59d7642751237e7c6f9605e2 (patch) | |
tree | 38e342735d6c2d29a04dc3d4a57fa8d5dc3b4a5e | |
parent | 7a645486ab1620e54709aa08db90c5e80bea8a44 (diff) | |
download | deluge-8bd576f6364738bc59d7642751237e7c6f9605e2.tar.gz deluge-8bd576f6364738bc59d7642751237e7c6f9605e2.tar.bz2 deluge-8bd576f6364738bc59d7642751237e7c6f9605e2.zip |
Fix [4491] which broke the oldstateupgrade
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | deluge/core/oldstateupgrader.py | 57 |
2 files changed, 32 insertions, 28 deletions
@@ -1,4 +1,7 @@ Deluge 1.1.1 - (In Development) + Core: + * Fix oldstateupgrader for those upgrading from 0.5.x + Misc: * Fix bdecoding some torrent files diff --git a/deluge/core/oldstateupgrader.py b/deluge/core/oldstateupgrader.py index f580b8398..489ce391e 100644 --- a/deluge/core/oldstateupgrader.py +++ b/deluge/core/oldstateupgrader.py @@ -76,29 +76,30 @@ class OldStateUpgrader: log.debug("Unable to open 0.5 state file: %s", e) return + # Check to see if we can upgrade this file if type(state).__name__ == 'list': - log.debug("0.5 state file is too old to upgrade:") + log.warning("0.5 state file is too old to upgrade") return - else: - new_state = deluge.core.torrentmanager.TorrentManagerState() - for ti, uid in state.torrents.items(): - torrent_path = os.path.join(self.config["config_location"], "torrentfiles", ti.filename) - try: - torrent_info = None - log.debug("Attempting to create torrent_info from %s", torrent_path) - _file = open(torrent_path, "rb") - torrent_info = lt.torrent_info(lt.bdecode(_file.read())) - _file.close() - except (IOError, RuntimeError), e: - log.warning("Unable to open %s: %s", filepath, e) + + new_state = deluge.core.torrentmanager.TorrentManagerState() + for ti, uid in state.torrents.items(): + torrent_path = os.path.join(self.config["config_location"], "torrentfiles", ti.filename) + try: + torrent_info = None + log.debug("Attempting to create torrent_info from %s", torrent_path) + _file = open(torrent_path, "rb") + torrent_info = lt.torrent_info(lt.bdecode(_file.read())) + _file.close() + except (IOError, RuntimeError), e: + log.warning("Unable to open %s: %s", filepath, e) # Copy the torrent file to the new location - import shutil - shutil.copyfile(torrent_path, os.path.join(self.config["state_location"], str(torrent_info.info_hash()) + ".torrent")) + import shutil + shutil.copyfile(torrent_path, os.path.join(self.config["state_location"], str(torrent_info.info_hash()) + ".torrent")) - # Set the file prioritiy property if not already there - if not hasattr(ti, "priorities"): - ti.priorities = [1] * torrent_info.num_files() + # Set the file prioritiy property if not already there + if not hasattr(ti, "priorities"): + ti.priorities = [1] * torrent_info.num_files() # Create the new TorrentState object new_torrent = deluge.core.torrentmanager.TorrentState( @@ -116,16 +117,16 @@ class OldStateUpgrader: # Append the object to the state list new_state.torrents.append(new_torrent) - # Now we need to write out the new state file - try: - log.debug("Saving torrent state file.") - state_file = open( - os.path.join(self.config["state_location"], "torrents.state"), "wb") - cPickle.dump(new_state, state_file) - state_file.close() - except IOError, e: - log.warning("Unable to save state file: %s", e) - return + # Now we need to write out the new state file + try: + log.debug("Saving torrent state file.") + state_file = open( + os.path.join(self.config["state_location"], "torrents.state"), "wb") + cPickle.dump(new_state, state_file) + state_file.close() + except IOError, e: + log.warning("Unable to save state file: %s", e) + return # Rename the persistent.state file try: |