def _notify(self, opaque, path, events_mask): self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join( self._inotify.humanReadableMask(events_mask)))) relpath_u = self._get_relpath(path) # We filter out IN_CREATE events not associated with a directory. # Acting on IN_CREATE for files could cause us to read and upload # a possibly-incomplete file before the application has closed it. # There should always be an IN_CLOSE_WRITE after an IN_CREATE, I think. # It isn't possible to avoid watching for IN_CREATE at all, because # it is the only event notified for a directory creation. if ((events_mask & self._inotify.IN_CREATE) != 0 and (events_mask & self._inotify.IN_ISDIR) == 0): self._log("ignoring event for %r (creation of non-directory)\n" % (relpath_u, )) return if relpath_u in self._pending: self._log("not queueing %r because it is already pending" % (relpath_u, )) return if magicpath.should_ignore_file(relpath_u): self._log("ignoring event for %r (ignorable path)" % (relpath_u, )) return self._add_pending(relpath_u) self._call_hook(path, 'inotify')
def test_should_ignore(self): self.failUnlessEqual(magicpath.should_ignore_file(u".bashrc"), True) self.failUnlessEqual(magicpath.should_ignore_file(u"bashrc."), False) self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/branch/.bashrc"), True) self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/.branch/bashrc"), True) self.failUnlessEqual(magicpath.should_ignore_file(u"forest/.tree/branch/bashrc"), True) self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/branch/bashrc"), False)
def _should_download(self, relpath_u, remote_version): """ _should_download returns a bool indicating whether or not a remote object should be downloaded. We check the remote metadata version against our magic-folder db version number; latest version wins. """ self._log("_should_download(%r, %r)" % (relpath_u, remote_version)) if magicpath.should_ignore_file(relpath_u): self._log("nope") return False self._log("yep") db_entry = self._db.get_db_entry(relpath_u) if db_entry is None: return True self._log("version %r" % (db_entry.version,)) return (db_entry.version < remote_version)
def _add_pending(self, relpath_u): self._log("add pending %r" % (relpath_u,)) if magicpath.should_ignore_file(relpath_u): self._log("_add_pending %r but should_ignore()==True" % (relpath_u,)) return if relpath_u in self._pending: self._log("_add_pending %r but already pending" % (relpath_u,)) return self._pending.add(relpath_u) progress = PercentProgress() item = UploadItem(relpath_u, progress) item.set_status('queued', self._clock.seconds()) self._deque.append(item) self._count('objects_queued') self._log("_add_pending(%r) queued item" % (relpath_u,))
def _should_download(self, relpath_u, remote_version): """ _should_download returns a bool indicating whether or not a remote object should be downloaded. We check the remote metadata version against our magic-folder db version number; latest version wins. """ self._log("_should_download(%r, %r)" % (relpath_u, remote_version)) if magicpath.should_ignore_file(relpath_u): self._log("nope") return False self._log("yep") db_entry = self._db.get_db_entry(relpath_u) if db_entry is None: return True self._log("version %r" % (db_entry.version, )) return (db_entry.version < remote_version)
def test_should_ignore(self): self.failUnlessEqual(magicpath.should_ignore_file(u".bashrc"), True) self.failUnlessEqual(magicpath.should_ignore_file(u"bashrc."), False) self.failUnlessEqual( magicpath.should_ignore_file(u"forest/tree/branch/.bashrc"), True) self.failUnlessEqual( magicpath.should_ignore_file(u"forest/tree/.branch/bashrc"), True) self.failUnlessEqual( magicpath.should_ignore_file(u"forest/.tree/branch/bashrc"), True) self.failUnlessEqual( magicpath.should_ignore_file(u"forest/tree/branch/bashrc"), False)
def _notify(self, opaque, path, events_mask): self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask)))) relpath_u = self._get_relpath(path) # We filter out IN_CREATE events not associated with a directory. # Acting on IN_CREATE for files could cause us to read and upload # a possibly-incomplete file before the application has closed it. # There should always be an IN_CLOSE_WRITE after an IN_CREATE, I think. # It isn't possible to avoid watching for IN_CREATE at all, because # it is the only event notified for a directory creation. if ((events_mask & self._inotify.IN_CREATE) != 0 and (events_mask & self._inotify.IN_ISDIR) == 0): self._log("ignoring event for %r (creation of non-directory)\n" % (relpath_u,)) return if relpath_u in self._pending: self._log("not queueing %r because it is already pending" % (relpath_u,)) return if magicpath.should_ignore_file(relpath_u): self._log("ignoring event for %r (ignorable path)" % (relpath_u,)) return self._add_pending(relpath_u)