mirror of https://github.com/borgbackup/borg.git
reduce code duplication
This commit is contained in:
parent
ae6742fb34
commit
0021052dbd
|
@ -777,7 +777,7 @@ Utilization of max. archive size: {csize_max:.0%}
|
|||
length = len(item.chunks)
|
||||
# the item should only have the *additional* chunks we processed after the last partial item:
|
||||
item.chunks = item.chunks[from_chunk:]
|
||||
item.size = sum(chunk.size for chunk in item.chunks)
|
||||
item.file_size(memorize=True)
|
||||
item.path += '.borg_part_%d' % number
|
||||
item.part = number
|
||||
number += 1
|
||||
|
@ -826,7 +826,7 @@ Utilization of max. archive size: {csize_max:.0%}
|
|||
)
|
||||
fd = sys.stdin.buffer # binary
|
||||
self.chunk_file(item, cache, self.stats, backup_io_iter(self.chunker.chunkify(fd)))
|
||||
item.size = sum(chunk.size for chunk in item.chunks)
|
||||
item.file_size(memorize=True)
|
||||
self.stats.nfiles += 1
|
||||
self.add_item(item)
|
||||
return 'i' # stdin
|
||||
|
@ -887,7 +887,7 @@ Utilization of max. archive size: {csize_max:.0%}
|
|||
cache.memorize_file(path_hash, st, [c.id for c in item.chunks])
|
||||
status = status or 'M' # regular file, modified (if not 'A' already)
|
||||
item.update(self.stat_attrs(st, path))
|
||||
item.size = sum(chunk.size for chunk in item.chunks)
|
||||
item.file_size(memorize=True)
|
||||
if is_special_file:
|
||||
# we processed a special file like a regular file. reflect that in mode,
|
||||
# so it can be extracted / accessed in FUSE mount like a regular file:
|
||||
|
|
|
@ -605,9 +605,7 @@ class Archiver:
|
|||
if consider_ids is not None: # consider only specific chunks
|
||||
size = sum(chunk.size for chunk in item.chunks if chunk.id in consider_ids)
|
||||
else: # consider all chunks
|
||||
size = item.get('size')
|
||||
if size is None:
|
||||
size = sum(chunk.size for chunk in item.chunks)
|
||||
size = item.file_size()
|
||||
return size
|
||||
|
||||
def get_owner(item):
|
||||
|
|
|
@ -1701,10 +1701,7 @@ class ItemFormatter(BaseFormatter):
|
|||
return len(item.get('chunks', []))
|
||||
|
||||
def calculate_size(self, item):
|
||||
size = item.get('size')
|
||||
if size is not None:
|
||||
return size
|
||||
return sum(c.size for c in item.get('chunks', []))
|
||||
return item.file_size()
|
||||
|
||||
def calculate_csize(self, item):
|
||||
return sum(c.csize for c in item.get('chunks', []))
|
||||
|
|
|
@ -172,16 +172,24 @@ class Item(PropDict):
|
|||
|
||||
part = PropDict._make_property('part', int)
|
||||
|
||||
def file_size(self, hardlink_masters=None):
|
||||
def file_size(self, hardlink_masters=None, memorize=False):
|
||||
"""determine the size of this item"""
|
||||
size = self.get('size')
|
||||
if size is not None:
|
||||
return size
|
||||
hardlink_masters = hardlink_masters or {}
|
||||
chunks, _ = hardlink_masters.get(self.get('source'), (None, None))
|
||||
chunks = self.get('chunks', chunks)
|
||||
if chunks is None:
|
||||
return 0
|
||||
return sum(chunk.size for chunk in chunks)
|
||||
chunks = self.get('chunks')
|
||||
having_chunks = chunks is not None
|
||||
if not having_chunks:
|
||||
# this item has no (own) chunks, but if this is a hardlink slave
|
||||
# and we know the master, we can still compute the size.
|
||||
hardlink_masters = hardlink_masters or {}
|
||||
chunks, _ = hardlink_masters.get(self.get('source'), (None, None))
|
||||
if chunks is None:
|
||||
return 0
|
||||
size = sum(chunk.size for chunk in chunks)
|
||||
if memorize and having_chunks:
|
||||
self.size = size
|
||||
return size
|
||||
|
||||
|
||||
class EncryptedKey(PropDict):
|
||||
|
|
Loading…
Reference in New Issue