Fix issue with removing items while iterating through the self.state

dictionary.
This commit is contained in:
Andrew Resch 2008-01-13 08:32:46 +00:00
parent 0d793e7f89
commit 1de14a1ce0
1 changed files with 12 additions and 4 deletions

View File

@ -913,20 +913,23 @@ Space:") + " " + nice_free)
ret = None # We return new added unique ID(s), or None ret = None # We return new added unique ID(s), or None
no_space = False no_space = False
to_remove = []
# Add torrents to core and unique_IDs # Add torrents to core and unique_IDs
for torrent in self.state.torrents: for torrent in self.state.torrents:
if not os.path.exists(torrent.filename): if not os.path.exists(torrent.filename):
print "Missing file: %s" % torrent.filename print "Missing file: %s" % torrent.filename
del self.state.torrents[torrent] to_remove.append(torrent)
continue continue
if torrent not in self.unique_IDs.values(): if torrent not in self.unique_IDs.values():
try: try:
unique_ID = deluge_core.add_torrent(torrent.filename, unique_ID = deluge_core.add_torrent(torrent.filename,
torrent.save_dir, torrent.save_dir,
torrent.compact) torrent.compact)
except DelugeError, e: except Exception, e:
del self.state.torrents[torrent] print "Unable to add torrent: ", e
raise e to_remove.append(torrent)
continue
ret = unique_ID ret = unique_ID
self.unique_IDs[unique_ID] = torrent self.unique_IDs[unique_ID] = torrent
self.state.torrents[torrent] = unique_ID self.state.torrents[torrent] = unique_ID
@ -944,6 +947,11 @@ Space:") + " " + nice_free)
os.remove(self.unique_IDs[unique_ID].filename + ".fastresume") os.remove(self.unique_IDs[unique_ID].filename + ".fastresume")
except: except:
pass pass
# Remove torrents from self.state because they were not added to the
# libtorrent session.
for torrent in to_remove:
del self.state.torrents[torrent]
# Remove torrents from core, unique_IDs and queue # Remove torrents from core, unique_IDs and queue
to_delete = [] to_delete = []