Beispiel #1
0
    def __add_local_files(self):
        for dirpath, dirnames, filenames in os.walk(self.root):
            for filename in filenames:
                path = os.path.join(dirpath, filename)
                relpath = self.__relpath(path)
                # look for
                # - files that we haven't seen before
                # - files with newer timestamps than our latest known version
                #
                # note that if a file has new content, but the timestamp is
                # unchanged since we last saw it, we won't add a new version,
                # but rather treat the current version as corrupt
                if (
                    relpath not in self.files or
                    ts_round(os.stat(path).st_mtime) > self.files[relpath].timestamp
                ):
                    self.update(relpath, {
                        "versions": [{
                            "timestamp": ts_round(os.stat(path).st_mtime),
                            "chunks": None,
                        }]
                    })

        for file in self.files.values():
            # "not supposed to be deleted, but it is" -> it has been
            # deleted while we weren't looking.
            if not file.deleted and not os.path.exists(file.fullpath):
                # We don't know when it was deleted, so add the deletion
                # tag as just after the last modification (ie, mark that
                # version as deleted, but any newer remote version takes
                # precedence)
                self.update(file.filename, {
                    "versions": [{
                        "timestamp": ts_round(file.timestamp + 1),
                        "chunks": [],
                        "deleted": True,
                    }]
                })
Beispiel #2
0
 def test(self):
     self.assertEqual(2, util.ts_round(1))
     self.assertEqual(2, util.ts_round(0.0001))
     self.assertEqual(2, util.ts_round(2))
     self.assertEqual(0, util.ts_round(0))