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

This commit is contained in:
Thomas Waldmann 2019-04-19 18:36:38 +02:00
parent df5641ad27
commit 502ebe63be
3 changed files with 13 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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: