ソースを参照

Merge pull request #2344 from ThomasWaldmann/fix-size-symlink

fix symlink item fs size computation
TW 8 年 前
コミット
6dab80218b
3 ファイル変更9 行追加2 行削除
  1. 5 0
      src/borg/item.pyx
  2. 2 0
      src/borg/testsuite/archiver.py
  3. 2 2
      src/borg/testsuite/item.py

+ 5 - 0
src/borg/item.pyx

@@ -1,3 +1,4 @@
+import stat
 from collections import namedtuple
 from collections import namedtuple
 
 
 from .constants import ITEM_KEYS
 from .constants import ITEM_KEYS
@@ -193,6 +194,10 @@ class Item(PropDict):
                 raise AttributeError
                 raise AttributeError
             size = getattr(self, attr)
             size = getattr(self, attr)
         except AttributeError:
         except AttributeError:
+            if stat.S_ISLNK(self.mode):
+                # get out of here quickly. symlinks have no own chunks, their fs size is the length of the target name.
+                # also, there is the dual-use issue of .source (#2343), so don't confuse it with a hardlink slave.
+                return len(self.source)
             # no precomputed (c)size value available, compute it:
             # no precomputed (c)size value available, compute it:
             try:
             try:
                 chunks = getattr(self, 'chunks')
                 chunks = getattr(self, 'chunks')

+ 2 - 0
src/borg/testsuite/archiver.py

@@ -1748,6 +1748,8 @@ class ArchiverTestCase(ArchiverTestCaseBase):
                 out_fn = os.path.join(mountpoint, 'input', 'link1')
                 out_fn = os.path.join(mountpoint, 'input', 'link1')
                 sti = os.stat(in_fn, follow_symlinks=False)
                 sti = os.stat(in_fn, follow_symlinks=False)
                 sto = os.stat(out_fn, follow_symlinks=False)
                 sto = os.stat(out_fn, follow_symlinks=False)
+                assert sti.st_size == len('somewhere')
+                assert sto.st_size == len('somewhere')
                 assert stat.S_ISLNK(sti.st_mode)
                 assert stat.S_ISLNK(sti.st_mode)
                 assert stat.S_ISLNK(sto.st_mode)
                 assert stat.S_ISLNK(sto.st_mode)
                 assert os.readlink(in_fn) == os.readlink(out_fn)
                 assert os.readlink(in_fn) == os.readlink(out_fn)

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

@@ -149,7 +149,7 @@ def test_unknown_property():
 
 
 
 
 def test_item_file_size():
 def test_item_file_size():
-    item = Item(chunks=[
+    item = Item(mode=0o100666, chunks=[
         ChunkListEntry(csize=1, size=1000, id=None),
         ChunkListEntry(csize=1, size=1000, id=None),
         ChunkListEntry(csize=1, size=2000, id=None),
         ChunkListEntry(csize=1, size=2000, id=None),
     ])
     ])
@@ -157,5 +157,5 @@ def test_item_file_size():
 
 
 
 
 def test_item_file_size_no_chunks():
 def test_item_file_size_no_chunks():
-    item = Item()
+    item = Item(mode=0o100666)
     assert item.get_size() == 0
     assert item.get_size() == 0