From: Brian Warner <warner@lothar.com>
Date: Wed, 27 Jan 2010 22:35:17 +0000 (-0800)
Subject: tahoe backup: skip all symlinks, with warning. Fixes #850, addresses #641.
X-Git-Tag: trac-4200~10
X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/?a=commitdiff_plain;h=e769bbb6dd41d40c1dbd2c098e7508bef67d45bf;p=tahoe-lafs%2Ftahoe-lafs.git

tahoe backup: skip all symlinks, with warning. Fixes #850, addresses #641.
---

diff --git a/src/allmydata/scripts/tahoe_backup.py b/src/allmydata/scripts/tahoe_backup.py
index ee8cb569..f816eedd 100644
--- a/src/allmydata/scripts/tahoe_backup.py
+++ b/src/allmydata/scripts/tahoe_backup.py
@@ -171,14 +171,15 @@ class BackerUpper:
         for child in self.options.filter_listdir(children):
             childpath = os.path.join(localpath, child)
             child = unicode(child)
-            if os.path.isdir(childpath):
+            # note: symlinks to directories are both islink() and isdir()
+            if os.path.isdir(childpath) and not os.path.islink(childpath):
                 metadata = get_local_metadata(childpath)
                 # recurse on the child directory
                 childcap = self.process(childpath)
                 assert isinstance(childcap, str)
                 create_contents[child] = ("dirnode", childcap, metadata)
                 compare_contents[child] = childcap
-            elif os.path.isfile(childpath):
+            elif os.path.isfile(childpath) and not os.path.islink(childpath):
                 try:
                     childcap, metadata = self.upload(childpath)
                     assert isinstance(childcap, str)
@@ -189,7 +190,10 @@ class BackerUpper:
                     self.warn("WARNING: permission denied on file %s" % childpath)
             else:
                 self.files_skipped += 1
-                self.warn("WARNING: cannot backup special file %s" % childpath)
+                if os.path.islink(childpath):
+                    self.warn("WARNING: cannot backup symlink %s" % childpath)
+                else:
+                    self.warn("WARNING: cannot backup special file %s" % childpath)
 
         must_create, r = self.check_backupdb_directory(compare_contents)
         if must_create:
diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py
index dc45e2fe..38ddbb69 100644
--- a/src/allmydata/test/test_cli.py
+++ b/src/allmydata/test/test_cli.py
@@ -1383,7 +1383,8 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
 
         def _check((rc, out, err)):
             self.failUnlessEqual(rc, 2)
-            self.failUnlessEqual(err, "WARNING: cannot backup special file %s\n" % os.path.join(source, "foo2.txt"))
+            foo2 = os.path.join(source, "foo2.txt")
+            self.failUnlessEqual(err, "WARNING: cannot backup symlink %s\n" % foo2)
 
             fu, fr, fs, dc, dr, ds = self.count_output(out)
             # foo.txt