]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/metadata.py
metadata: fix symlink stat() vs. readlink() race
[bup.git] / lib / bup / metadata.py
index d799cc4b645ad94db474846c3adedc5beab0d44e..67f3a079d9480aab29a876d76e175eb27624456b 100644 (file)
@@ -479,6 +479,9 @@ class Metadata:
         try:
             if stat.S_ISLNK(st.st_mode):
                 self.symlink_target = os.readlink(path)
+                # might have read a different link than the
+                # one that was in place when we did stat()
+                self.size = len(self.symlink_target)
         except OSError as e:
             add_error('readlink: %s' % e)
 
@@ -885,6 +888,7 @@ class Metadata:
 def from_path(path, statinfo=None, archive_path=None,
               save_symlinks=True, hardlink_target=None,
               normalized=False):
+    # This function is also a test hook; see test-save-errors
     """Return the metadata associated with the path.  When normalized is
     true, return the metadata appropriate for a typical save, which
     may or may not be all of it."""