示例#1
0
 def _snapshot_add_missing_files(self, *, src_files, dst_files):
     existing = 0
     disappeared = 0
     changes = 0
     for i, relative_path in enumerate(set(src_files).difference(dst_files), 1):
         src_path = self.src / relative_path
         dst_path = self.dst / relative_path
         try:
             os.link(src=src_path, dst=dst_path, follow_symlinks=False)
         except FileExistsError:
             # This happens only if snapshot is started twice at
             # same time. While it is technically speaking upstream
             # error, we rather handle it here than leave
             # exceptions not handled.
             existing += 1
             if increase_worth_reporting(existing):
                 logger.debug("#%d. %s already existed, ignoring", existing, src_path)
             continue
         except FileNotFoundError:
             disappeared += 1
             if increase_worth_reporting(disappeared):
                 logger.debug("#%d. %s disappeared before linking, ignoring", disappeared, src_path)
             continue
         if increase_worth_reporting(i - disappeared):
             logger.debug("#%d. new file: %r", i - disappeared, relative_path)
         changes += 1
     return changes
示例#2
0
 def _snapshot_create_missing_directories(self, *, src_dirs, dst_dirs):
     changes = 0
     for i, relative_dir in enumerate(set(src_dirs).difference(dst_dirs), 1):
         dst_path = self.dst / relative_dir
         dst_path.mkdir(parents=True, exist_ok=True)
         if increase_worth_reporting(i):
             logger.debug("#%d. new directory: %r", i, relative_dir)
         changes += 1
     return changes
示例#3
0
 def _snapshot_remove_extra_files(self, *, src_files, dst_files):
     changes = 0
     for i, relative_path in enumerate(set(dst_files).difference(src_files), 1):
         dst_path = self.dst / relative_path
         snapshotfile = self.relative_path_to_snapshotfile.get(relative_path)
         if snapshotfile:
             self._remove_snapshotfile(snapshotfile)
         dst_path.unlink()
         if increase_worth_reporting(i):
             logger.debug("#%d. extra file: %r", i, relative_path)
         changes += 1
     return changes
示例#4
0
 def _get_snapshot_hash_list(self, relative_paths):
     same = 0
     lost = 0
     for relative_path in relative_paths:
         old_snapshotfile = self.relative_path_to_snapshotfile.get(relative_path)
         try:
             snapshotfile = self._snapshotfile_from_path(relative_path)
         except FileNotFoundError:
             lost += 1
             if increase_worth_reporting(lost):
                 logger.debug("#%d. lost - %s disappeared before stat, ignoring", lost, self.src / relative_path)
             continue
         if old_snapshotfile:
             snapshotfile.hexdigest = old_snapshotfile.hexdigest
             snapshotfile.content_b64 = old_snapshotfile.content_b64
             if old_snapshotfile == snapshotfile:
                 same += 1
                 if increase_worth_reporting(same):
                     logger.debug("#%d. same - %r in %s is same", same, old_snapshotfile, relative_path)
                 continue
         yield snapshotfile
示例#5
0
def test_increase_worth_reporting(old_value, new_value, total, exp):
    assert progress.increase_worth_reporting(old_value, new_value,
                                             total=total) == exp