Browse Source

delete archive: consider part files correctly for stats, see #4507

Thomas Waldmann 6 years ago
parent
commit
502ebe63be
3 changed files with 13 additions and 11 deletions
  1. 4 3
      src/borg/archive.py
  2. 3 2
      src/borg/archiver.py
  3. 6 6
      src/borg/cache.py

+ 4 - 3
src/borg/archive.py

@@ -845,9 +845,9 @@ Utilization of max. archive size: {csize_max:.0%}
                 error = True
                 return exception_ignored  # must not return None here
 
-        def chunk_decref(id, stats):
+        def chunk_decref(id, stats, part=False):
             try:
-                self.cache.chunk_decref(id, stats, wait=False)
+                self.cache.chunk_decref(id, stats, wait=False, part=part)
             except KeyError:
                 cid = bin_to_hex(id)
                 raise ChunksIndexError(cid)
@@ -869,8 +869,9 @@ Utilization of max. archive size: {csize_max:.0%}
                     for item in unpacker:
                         item = Item(internal_dict=item)
                         if 'chunks' in item:
+                            part = not self.consider_part_files and 'part' in item
                             for chunk_id, size, csize in item.chunks:
-                                chunk_decref(chunk_id, stats)
+                                chunk_decref(chunk_id, stats, part=part)
                 except (TypeError, ValueError):
                     # if items metadata spans multiple chunks and one chunk got dropped somehow,
                     # it could be that unpacker yields bad types

+ 3 - 2
src/borg/archiver.py

@@ -1132,8 +1132,9 @@ class Archiver:
                 msg = 'Would delete archive: {} ({}/{})' if dry_run else 'Deleting archive: {} ({}/{})'
                 logger.info(msg.format(format_archive(manifest.archives[archive_name]), i, len(archive_names)))
                 if not dry_run:
-                    Archive(repository, key, manifest, archive_name, cache=cache).delete(
-                        stats, progress=args.progress, forced=args.forced)
+                    archive = Archive(repository, key, manifest, archive_name, cache=cache,
+                                      consider_part_files=args.consider_part_files)
+                    archive.delete(stats, progress=args.progress, forced=args.forced)
             if not dry_run:
                 manifest.write()
                 repository.commit(compact=False, save_space=args.save_space)

+ 6 - 6
src/borg/cache.py

@@ -909,16 +909,16 @@ class LocalCache(CacheStatsMixin):
         stats.update(_size, csize, False, part=part)
         return ChunkListEntry(id, _size, csize)
 
-    def chunk_decref(self, id, stats, wait=True):
+    def chunk_decref(self, id, stats, wait=True, part=False):
         if not self.txn_active:
             self.begin_txn()
         count, size, csize = self.chunks.decref(id)
         if count == 0:
             del self.chunks[id]
             self.repository.delete(id, wait=wait)
-            stats.update(-size, -csize, True)
+            stats.update(-size, -csize, True, part=part)
         else:
-            stats.update(-size, -csize, False)
+            stats.update(-size, -csize, False, part=part)
 
     def file_known_and_unchanged(self, path_hash, st):
         """
@@ -1057,16 +1057,16 @@ Chunk index:    {0.total_unique_chunks:20d}             unknown"""
         stats.update(size, csize, False, part=part)
         return ChunkListEntry(id, size, csize)
 
-    def chunk_decref(self, id, stats, wait=True):
+    def chunk_decref(self, id, stats, wait=True, part=False):
         if not self._txn_active:
             self.begin_txn()
         count, size, csize = self.chunks.decref(id)
         if count == 0:
             del self.chunks[id]
             self.repository.delete(id, wait=wait)
-            stats.update(-size, -csize, True)
+            stats.update(-size, -csize, True, part=part)
         else:
-            stats.update(-size, -csize, False)
+            stats.update(-size, -csize, False, part=part)
 
     def commit(self):
         if not self._txn_active: