Fix #1341 issue where Config would try to cancel the save_timer when it is None.
This commit is contained in:
parent
ca5eaf4270
commit
01773e433f
|
@ -396,15 +396,13 @@ what is currently in the config and it could not convert the value
|
|||
version = json.loads(data[start:end])
|
||||
start, end = objects[1]
|
||||
loaded_data = json.loads(data[start:end])
|
||||
|
||||
if self.__config == loaded_data and self.__version == version:
|
||||
# The config has not changed so lets just return
|
||||
self._save_timer.cancel()
|
||||
if self._save_timer:
|
||||
self._save_timer.cancel()
|
||||
return
|
||||
except Exception, e:
|
||||
log.warning("Unable to open config file: %s", filename)
|
||||
|
||||
|
||||
except IOError, e:
|
||||
log.warning("Unable to open config file: %s because: %s", filename, e)
|
||||
|
||||
# Save the new config and make sure it's written to disk
|
||||
try:
|
||||
|
@ -415,7 +413,7 @@ what is currently in the config and it could not convert the value
|
|||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
f.close()
|
||||
except Exception, e:
|
||||
except IOError, e:
|
||||
log.error("Error writing new config file: %s", e)
|
||||
return False
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import os
|
|||
|
||||
from deluge.config import Config
|
||||
|
||||
DEFAULTS = {"string": "foobar", "int": 1, "float": 0.435, "bool": True, "tuple": (1, 2)}
|
||||
DEFAULTS = {"string": "foobar", "int": 1, "float": 0.435, "bool": True}
|
||||
|
||||
class ConfigTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -69,6 +69,13 @@ class ConfigTestCase(unittest.TestCase):
|
|||
|
||||
def test_save(self):
|
||||
config = Config("test.conf", defaults=DEFAULTS, config_dir=self.config_dir)
|
||||
# We do this twice because the first time we need to save the file to disk
|
||||
# and the second time we do a compare and we should not write
|
||||
ret = config.save()
|
||||
self.assertTrue(ret)
|
||||
ret = config.save()
|
||||
self.assertTrue(ret)
|
||||
|
||||
config["string"] = "baz"
|
||||
config["int"] = 2
|
||||
ret = config.save()
|
||||
|
@ -111,4 +118,3 @@ class ConfigTestCase(unittest.TestCase):
|
|||
|
||||
objects = find_json_objects(s)
|
||||
self.assertEquals(len(objects), 2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue