diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-26 22:44:58 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-26 22:44:58 -0500 |
commit | 1217539f47c923a22434e05eaa9e271696c6a637 (patch) | |
tree | 7ee3a220a29108bd716837bf780bdf95ff73594f /combox/events.py | |
parent | 65bd4237e892441a6e143b7d8b7b7a3541118850 (diff) |
fleshed out the NodeDirMonitor's on_modified method + wrote tests for it.
modified: combox/events.py
modified: tests/events_test.py
Diffstat (limited to 'combox/events.py')
-rw-r--r-- | combox/events.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/combox/events.py b/combox/events.py index 779b6f6..3692adc 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) + cb_path, node_path, hash_file) from combox.silo import ComboxSilo @@ -179,6 +179,13 @@ class NodeDirMonitor(LoggingEventHandler): self.silo = ComboxSilo(self.config) + def silo_update(self): + """ + Re-reads the silo from disk. + """ + self.silo = ComboxSilo(self.config) + + def housekeep(self): """Recursively traverses node directory, discovers changes and updates silo and combox directory. @@ -230,4 +237,25 @@ class NodeDirMonitor(LoggingEventHandler): def on_modified(self, event): super(NodeDirMonitor, self).on_modified(event) - pass + self.silo_update() + + file_cb_path = cb_path(event.src_path, self.config) + + if event.is_directory: + # do nothing + pass + elif (not event.is_directory): + file_content = decrypt_and_glue(file_cb_path, + self.config, + write=False) + file_content_hash = hash_file(file_cb_path, file_content) + + if self.silo.stale(file_cb_path, file_content_hash): + # shard modified + + # means, file was modified on another computer (also + # running combox). so, reconstruct the file and put it + # in the combox directory. + decrypt_and_glue(file_cb_path, self.config) + # update db. + self.silo.update(file_cb_path) |