Fix #47 the state and config files are no longer invalidated when there

is no diskspace
This commit is contained in:
Andrew Resch 2008-11-28 23:36:18 +00:00
parent 1440d6b247
commit 4933618f50
1 changed files with 12 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import cPickle
import os.path import os.path
import os import os
import time import time
import shutil
import gobject import gobject
@ -531,12 +532,22 @@ class TorrentManager(component.Component):
try: try:
log.debug("Saving torrent state file.") log.debug("Saving torrent state file.")
state_file = open( state_file = open(
os.path.join(self.config["state_location"], "torrents.state"), os.path.join(self.config["state_location"], "torrents.state.new"),
"wb") "wb")
cPickle.dump(state, state_file) cPickle.dump(state, state_file)
state_file.close() state_file.close()
except IOError: except IOError:
log.warning("Unable to save state file.") log.warning("Unable to save state file.")
return True
# We have to move the 'torrents.state.new' file to 'torrents.state'
try:
shutil.move(
os.path.join(self.config["state_location"], "torrents.state.new"),
os.path.join(self.config["state_location"], "torrents.state"))
except IOError:
log.warning("Unable to save state file.")
return True
# We return True so that the timer thread will continue # We return True so that the timer thread will continue
return True return True