Kaynağa Gözat

rename Item.file_size -> get_size

file_size is misleading here because one thinks of on-disk file size,
but for compressed=True, there is no such on-disk file.
Thomas Waldmann 8 yıl önce
ebeveyn
işleme
50068c596d

+ 3 - 3
src/borg/archive.py

@@ -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.file_size(memorize=True)
+        item.get_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.file_size(memorize=True)
+        item.get_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.file_size(memorize=True)
+        item.get_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:

+ 2 - 2
src/borg/archiver.py

@@ -541,7 +541,7 @@ class Archiver:
         if progress:
             pi = ProgressIndicatorPercent(msg='%5.1f%% Extracting: %s', step=0.1)
             pi.output('Calculating size')
-            extracted_size = sum(item.file_size(hardlink_masters) for item in archive.iter_items(filter))
+            extracted_size = sum(item.get_size(hardlink_masters) for item in archive.iter_items(filter))
             pi.total = extracted_size
         else:
             pi = None
@@ -605,7 +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.file_size()
+                    size = item.get_size()
             return size
 
         def get_owner(item):

+ 1 - 1
src/borg/fuse.py

@@ -266,7 +266,7 @@ class FuseOperations(llfuse.Operations):
         entry.st_uid = item.uid
         entry.st_gid = item.gid
         entry.st_rdev = item.get('rdev', 0)
-        entry.st_size = item.file_size()
+        entry.st_size = item.get_size()
         entry.st_blksize = 512
         entry.st_blocks = (entry.st_size + entry.st_blksize - 1) // entry.st_blksize
         # note: older archives only have mtime (not atime nor ctime)

+ 2 - 2
src/borg/helpers.py

@@ -1702,11 +1702,11 @@ class ItemFormatter(BaseFormatter):
 
     def calculate_size(self, item):
         # note: does not support hardlink slaves, they will be size 0
-        return item.file_size(compressed=False)
+        return item.get_size(compressed=False)
 
     def calculate_csize(self, item):
         # note: does not support hardlink slaves, they will be csize 0
-        return item.file_size(compressed=True)
+        return item.get_size(compressed=True)
 
     def hash_item(self, hash_function, item):
         if 'chunks' not in item:

+ 9 - 2
src/borg/item.pyx

@@ -176,8 +176,15 @@ class Item(PropDict):
 
     part = PropDict._make_property('part', int)
 
-    def file_size(self, hardlink_masters=None, memorize=False, compressed=False):
-        """determine the (uncompressed or compressed) size of this item"""
+    def get_size(self, hardlink_masters=None, memorize=False, compressed=False):
+        """
+        Determine the (uncompressed or compressed) size of this item.
+
+        For hardlink slaves, the size is computed via the hardlink master's
+        chunk list, if available (otherwise size will be returned as 0).
+
+        If memorize is True, the computed size value will be stored into the item.
+        """
         attr = 'csize' if compressed else 'size'
         try:
             size = getattr(self, attr)

+ 2 - 2
src/borg/testsuite/item.py

@@ -142,9 +142,9 @@ def test_item_file_size():
         ChunkListEntry(csize=1, size=1000, id=None),
         ChunkListEntry(csize=1, size=2000, id=None),
     ])
-    assert item.file_size() == 3000
+    assert item.get_size() == 3000
 
 
 def test_item_file_size_no_chunks():
     item = Item()
-    assert item.file_size() == 0
+    assert item.get_size() == 0