diff options
-rw-r--r-- | TODO.org | 5 | ||||
-rw-r--r-- | combox/events.py | 27 | ||||
-rw-r--r-- | tests/events_test.py | 15 | ||||
-rw-r--r-- | tests/utils.py | 12 |
4 files changed, 56 insertions, 3 deletions
@@ -11,7 +11,10 @@ Thanks to Dr. Green for finding this. [1]: http://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python -**** TODO combox not handling temprorary files created by editors properly :b#2: +**** DONE combox not handling temprorary files created by editors properly :b#2: + CLOSED: [2015-09-29 Tue 14:15] + - CLOSING NOTE [2015-09-29 Tue 14:15] \\ + Done. **** TODO config has problems creating nested node directories :b#3: **** DONE NodeDirMonitor.on_modified assums shard 0 is always available :b#4: CLOSED: [2015-08-25 Tue 23:21] diff --git a/combox/events.py b/combox/events.py index 32bbc52..21df86e 100644 --- a/combox/events.py +++ b/combox/events.py @@ -56,6 +56,20 @@ class ComboxDirMonitor(LoggingEventHandler): self.housekeep() + def tmp_file(self, file_path): + """Returns True if `file_path` is a tmp file.""" + + if file_path.endswith("~"): + return True + elif file_path.startswith(".#"): + return True + elif (file_path.startswith("#") and + file_path.endswith("#")): + return True + else: + return False + + def housekeep(self): """Recursively traverses combox directory, discovers changes and updates silo and node directories. @@ -100,7 +114,8 @@ class ComboxDirMonitor(LoggingEventHandler): print fpath, "was modified. Updating DB and shards..." split_and_encrypt(fpath, self.config) self.silo.update(fpath) - elif not self.silo.exists(fpath): + elif (not self.silo.exists(fpath) + and not self.tmp_file(fpath)): # new file print 'Adding new file', fpath, '...' split_and_encrypt(fpath, self.config) @@ -128,6 +143,11 @@ class ComboxDirMonitor(LoggingEventHandler): def on_created(self, event): super(ComboxDirMonitor, self).on_created(event) + if self.tmp_file(event.src_path): + # ignore tmp files. + print "Created tmp file", event.src_path, "...ignoring" + return + file_node_path = node_path(event.src_path, self.config, not event.is_directory) @@ -162,6 +182,11 @@ class ComboxDirMonitor(LoggingEventHandler): def on_modified(self, event): super(ComboxDirMonitor, self).on_modified(event) + if self.tmp_file(event.src_path): + # ignore tmp files. + print "Modified tmp file", event.src_path, "...ignoring" + return + if event.is_directory: # do nothing pass diff --git a/tests/events_test.py b/tests/events_test.py index 16467b2..7daabff 100644 --- a/tests/events_test.py +++ b/tests/events_test.py @@ -42,7 +42,7 @@ from combox.file import (relative_path, purge_dir, hash_file, from combox.silo import ComboxSilo from tests.utils import (get_config, shardedp, dirp, renamedp, path_deletedp, rm_nodedirs, rm_configdir, - purge_nodedirs, purge) + purge_nodedirs, purge, not_shardedp) class TestEvents(object): @@ -94,6 +94,19 @@ class TestEvents(object): silo = ComboxSilo(self.config, self.silo_lock) assert silo.exists(self.TEST_FILE_COPY_0) + # Test - tmp file creation. + # combox must ignore it. + self.TEST_TMP_FILE = "%s~" % self.TEST_FILE + copyfile(self.TEST_FILE, self.TEST_TMP_FILE) + # wait for a second. + time.sleep(1) + ## confirm that shards were not created. + not_shardedp(self.TEST_TMP_FILE) + ## confirm that it did not get registered in the silo. + assert not silo.exists(self.TEST_TMP_FILE) + # purge it later. + self.purge_list.append(self.TEST_TMP_FILE) + # Test - File deletion. remove(self.TEST_FILE_COPY_0) time.sleep(1) diff --git a/tests/utils.py b/tests/utils.py index dc7a309..3f46813 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -109,6 +109,18 @@ def shardedp(f): assert path.exists(shard) and path.isfile(shard) +def not_shardedp(f): + """Checks if file's shards does not exists in the node directories""" + config = get_config() + nodes = get_nodedirs(config) + i = 0 + for node in nodes: + rel_path = relative_path(f, config) + shard = "%s.shard%s" % (path.join(node, rel_path), i) + i += 1 + assert not path.exists(shard) and not path.isfile(shard) + + def dirp(d): """ Checks if the directory was created under node directories |