From 54d70dad75387e0369c2b67dacff80d32d3cfc1e Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Tue, 29 Sep 2015 14:15:49 -0400 Subject: [bug fix] fix for :b#2: Now combox ignores tmp files created by editors. modified: TODO.org modified: combox/events.py modified: tests/events_test.py modified: tests/utils.py --- combox/events.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'combox') 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 -- cgit v1.2.3