summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combox/silo.py8
-rw-r--r--tests/silo_test.py3
2 files changed, 7 insertions, 4 deletions
diff --git a/combox/silo.py b/combox/silo.py
index b1e59f6..21b473d 100644
--- a/combox/silo.py
+++ b/combox/silo.py
@@ -84,17 +84,19 @@ class ComboxSilo(object):
return True
- def stale(self, filep):
+ def stale(self, filep, fhash=None):
"""Returns True if filep's hash is different from the hash stored in db.
Returns None, if filep's info is not yet stored in db.
Returns False, if filep's hash has not changed it.
filep: path to the file in combox directory.
-
+ fhash: If not None, it is assumed to be filep's hash.
"""
- fhash = hash_file(filep)
+ if not fhash:
+ fhash = hash_file(filep)
+
fhash_in_db = self.db.get(filep)
if fhash_in_db is None:
diff --git a/tests/silo_test.py b/tests/silo_test.py
index df905b6..1a290b4 100644
--- a/tests/silo_test.py
+++ b/tests/silo_test.py
@@ -22,7 +22,7 @@ from shutil import copyfile
from os import path, remove
from combox.silo import ComboxSilo
-from combox.file import read_file, write_file
+from combox.file import read_file, write_file, hash_file
from tests.utils import get_config, rm_nodedirs, rm_configdir
@@ -77,6 +77,7 @@ class TestSilo(object):
write_file(self.LOREM_IPSUM, lorem_ipsum_content)
assert csilo.stale(self.LOREM_IPSUM)
+ assert csilo.stale(self.LOREM_IPSUM, hash_file(self.LOREM_IPSUM))
csilo.update(self.LOREM_IPSUM)
assert csilo.stale(self.LOREM_IPSUM) is False