from allmydata import backupdb, magicpath
+IN_EXCL_UNLINK = 0x04000000L
+
def get_inotify_module():
try:
if sys.platform == "win32":
# possibly-incomplete file before the application has closed it. There should always
# be an IN_CLOSE_WRITE after an IN_CREATE (I think).
# TODO: what about IN_MOVE_SELF or IN_UNMOUNT?
- self.mask = inotify.IN_CLOSE_WRITE | inotify.IN_MOVED_TO | inotify.IN_ONLYDIR
+ #self.mask = inotify.IN_CLOSE_WRITE | inotify.IN_MOVED_TO | inotify.IN_ONLYDIR
+ #self.mask = inotify.IN_CLOSE_WRITE | inotify.IN_MOVED_TO | inotify.IN_MOVED_FROM | inotify.IN_ONLYDIR | IN_EXCL_UNLINK
+ self.mask = inotify.IN_CLOSE_WRITE | inotify.IN_MOVED_TO | inotify.IN_ONLYDIR | IN_EXCL_UNLINK | inotify.IN_DELETE
self._notifier.watch(self._local_path, mask=self.mask, callbacks=[self._notify],
recursive=True)
d2 = defer.Deferred()
self.uploader.set_uploaded_callback(d2.callback, ignore_count=0)
os.rename(empty_tree_dir, new_empty_tree_dir)
- self.notify(to_filepath(new_empty_tree_dir), self.inotify.IN_CLOSE_WRITE) # XXX
+ self.notify(to_filepath(new_empty_tree_dir), self.inotify.IN_MOVED_TO)
return d2
d.addCallback(_check_move_empty_tree)
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 1))
d2 = defer.Deferred()
self.uploader.set_uploaded_callback(d2.callback, ignore_count=1)
os.rename(small_tree_dir, new_small_tree_dir)
- self.notify(to_filepath(new_small_tree_dir), self.inotify.IN_CLOSE_WRITE)
+ self.notify(to_filepath(new_small_tree_dir), self.inotify.IN_MOVED_TO)
return d2
d.addCallback(_check_move_small_tree)
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 3))
d2 = defer.Deferred()
self.uploader.set_uploaded_callback(d2.callback, ignore_count=0)
os.rename(empty_tree_dir, new_empty_tree_dir)
- self.notify(to_filepath(new_empty_tree_dir), self.inotify.IN_CLOSE_WRITE) # XXX
+ self.notify(to_filepath(new_empty_tree_dir), self.inotify.IN_MOVED_TO)
return d2
d.addCallback(_check_move_empty_tree)
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 1))
def _move_dir_away(ign):
os.rename(new_empty_tree_dir, empty_tree_dir)
- self.notify(to_filepath(new_empty_tree_dir), self.inotify.IN_CLOSE_WRITE) # XXX
+ self.notify(to_filepath(new_empty_tree_dir), self.inotify.IN_MOVED_FROM)
d.addCallback(_move_dir_away)
def create_file(val):
return d2
d.addCallback(create_file)
def sleep_a_while(ign):
- time.sleep(3)
+ print "\ncalling time.sleep(5) to give the upload a chance..."
+ time.sleep(5)
d.addCallback(sleep_a_while)
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 1))
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.files_uploaded'), 0))
# Write to the same file again with different data.
d.addCallback(lambda ign: self._check_file(u"short", "different"))
-
+
# Test that temporary files are not uploaded.
d.addCallback(lambda ign: self._check_file(u"tempfile", "test", temporary=True))
f.close()
if temporary and sys.platform == "win32":
os.unlink(path_u)
+ self.notify(path, self.inotify.IN_DELETE)
fileutil.flush_volume(path_u)
self.notify(path, self.inotify.IN_CLOSE_WRITE)
if temporary:
d.addCallback(lambda ign: self.shouldFail(NoSuchChildError, 'temp file not uploaded', None,
- self.upload_dirnode.get, name_u))
+ self.upload_dirnode.get, name_u))
d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_disappeared'),
previously_disappeared + 1))
else: