diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-03-04 23:02:46 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-03-04 23:02:46 -0500 |
commit | 833577f45c9ae7062334b633eaeb3a8ca1ff3fdd (patch) | |
tree | 6cf2ba65e64ad1f3cabd0c8bc95ae815aee12492 | |
parent | a3f2d142280e83f31e5f418581fb44870cab4317 (diff) |
fleshed out the on_delete method in combox.events.NodeDirMonitor
As usual, wrote correponding tests for it :|
modified: combox/events.py
modified: tests/events_test.py
-rw-r--r-- | combox/events.py | 15 | ||||
-rw-r--r-- | tests/events_test.py | 17 |
2 files changed, 28 insertions, 4 deletions
diff --git a/combox/events.py b/combox/events.py index 662abaf..6b17dcf 100644 --- a/combox/events.py +++ b/combox/events.py @@ -26,7 +26,7 @@ from watchdog.events import LoggingEventHandler from combox.crypto import split_and_encrypt, decrypt_and_glue from combox.file import (mk_nodedir, rm_nodedir, rm_shards, relative_path, move_shards, move_nodedir, - cb_path, node_path, hash_file) + cb_path, node_path, hash_file, rm_path) from combox.silo import ComboxSilo @@ -244,9 +244,20 @@ class NodeDirMonitor(LoggingEventHandler): def on_deleted(self, event): - super(ComboxDirMonitor, self).on_deleted(event) + super(NodeDirMonitor, self).on_deleted(event) self.silo_update() + file_cb_path = cb_path(event.src_path, self.config) + + if event.is_directory: + # Delete corresponding directory under the combox directory. + rm_path(file_cb_path) + else: + # remove the corresponding file under the combox directory. + rm_path(file_cb_path) + # remove file info from silo. + self.silo.remove(file_cb_path) + def on_modified(self, event): super(NodeDirMonitor, self).on_modified(event) diff --git a/tests/events_test.py b/tests/events_test.py index f645e75..6ba768b 100644 --- a/tests/events_test.py +++ b/tests/events_test.py @@ -33,7 +33,7 @@ from combox.crypto import decrypt_and_glue, split_and_encrypt from combox.events import ComboxDirMonitor, NodeDirMonitor from combox.file import (relative_path, purge_dir, read_file, write_file, - rm_shards, mk_nodedir) + rm_shards, mk_nodedir, rm_nodedir) from combox.silo import ComboxSilo from tests.utils import (get_config, shardedp, dirp, renamedp, @@ -263,9 +263,22 @@ class TestEvents(object): ## check if BAR_DIR is created under the combox directory. assert path.isdir(self.BAR_DIR) - self.purge_list.append(self.TEST_FILE_MUTANT) self.purge_list.append(self.FOO_DIR) + # Test - Shard deletion. + rm_shards(self.TEST_FILE_MUTANT, self.config) + time.sleep(1) + assert not path.exists(self.TEST_FILE_MUTANT) + + ## check if the new file's info is removed from silo + silo = ComboxSilo(self.config) + assert not silo.exists(self.TEST_FILE_MUTANT) + + # Test - directory deletion inside node directory + rm_nodedir(self.BAR_DIR, self.config) + time.sleep(1) + assert not path.exists(self.BAR_DIR) + # Test - shard modification self.lorem_file = path.join(self.FILES_DIR, 'lorem.txt') lorem_content = read_file(self.lorem_file) |