combox

split and encrypted files between online file storage providers
git clone git://git.ricketyspace.net/combox.git
Log | Files | Refs

commit 098ae99641d5c848af1d0d25c29b254e7cd9d12e
parent 7c29a7dc5f592aff38e4c71a777a8cd6fdac9daf
Author: Siddharth Ravikumar <sravik@bgsu.edu>
Date:   Wed, 15 Apr 2015 20:48:47 -0400

rewrote combox.events.NodeDirMonitor.on_deleted method.

  - Now the the node monitor waits for all shards of the file, which
    was deleted on a remote computer, to get deleted on this computer,
    before it finally deletes the respective file in the combox
    directory.

  - Tests for it is at tests.events_test.TestEvents.test_NDM_ondeleted
    method.

	modified:   combox/events.py
	modified:   tests/events_test.py

Did some of this while listening to Cat Stevens' (Yusuf):

	- Just Another Night
	- Wild World
	- Father and son (*)
	- Peace train
	- Moonshadow (*)

Diffstat:
combox/events.py | 26++++++++++++++++++++------
tests/events_test.py | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/combox/events.py b/combox/events.py @@ -339,13 +339,27 @@ class NodeDirMonitor(LoggingEventHandler): 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) + with self.lock: + self.silo.node_set('file_deleted', file_cb_path) + num = self.silo.node_get('file_deleted', file_cb_path) + + if num == self.num_nodes: + # Delete corresponding directory under the combox + # directory. + rm_path(file_cb_path) + self.silo.node_rem('file_deleted', file_cb_path) elif not event.is_directory and path.exists(file_cb_path): - # remove the corresponding file under the combox directory. - rm_path(file_cb_path) - # remove file info from silo. - self.silo.remove(file_cb_path) + with self.lock: + self.silo.node_set('file_deleted', file_cb_path) + num = self.silo.node_get('file_deleted', file_cb_path) + + if num == self.num_nodes: + # remove the corresponding file under the combox + # directory. + rm_path(file_cb_path) + # remove file info from silo. + self.silo.remove(file_cb_path) + self.silo.node_rem('file_deleted', file_cb_path) def on_modified(self, event): diff --git a/tests/events_test.py b/tests/events_test.py @@ -361,6 +361,61 @@ class TestEvents(object): observers[i].join() + def test_NDM_ondeleted(self): + """Testing on_modified method in NodeDirMonitor""" + nodes = get_nodedirs(self.config) + num_nodes = len(get_nodedirs(self.config)) + + nmonitors = [] + observers = [] + + # create an observer for each node directory and make it + # monitor them. + for node in nodes: + nmonitor = NodeDirMonitor(self.config, self.silo_lock, + self.nodem_lock) + observer = Observer() + observer.schedule(nmonitor, node, recursive=True) + observer.start() + + nmonitors.append(nmonitor) + observers.append(observer) + + BAR_DIR = path.join(self.FILES_DIR, 'bar') + mk_nodedir(BAR_DIR, self.config) + # wait for the `bar' directory to be created inside combox + # directory. + time.sleep(1) + + # Test - directory deletion inside node directory. + rm_nodedir(BAR_DIR, self.config) + time.sleep(1) + assert not path.exists(BAR_DIR) + + the_guide = path.join(self.FILES_DIR, 'the.guide') + split_and_encrypt(the_guide, self.config, + read_file(self.TEST_FILE)) + time.sleep(1) + assert path.exists(the_guide) + + # Test - Shard deletion. + rm_shards(the_guide, self.config) + time.sleep(1) + assert not path.exists(the_guide) + + ## check if the new file's info is removed from silo + silo = ComboxSilo(self.config, self.silo_lock) + assert not silo.exists(the_guide) + + self.purge_list.append(BAR_DIR) + self.purge_list.append(the_guide) + + # stop the zarking observers. + for i in range(num_nodes): + observers[i].stop() + observers[i].join() + + def untest_NDM(self): """ Tests the NodeDirMonitor class.