]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
tahoe backup: perform tilde expansion in exclude-from filename (version 2). fixes...
authordavid-sarah <david-sarah@jacaranda.org>
Sun, 31 Oct 2010 03:52:31 +0000 (20:52 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Sun, 31 Oct 2010 03:52:31 +0000 (20:52 -0700)
src/allmydata/scripts/cli.py
src/allmydata/test/test_cli.py

index bb0f4db2d1997b9cfb57c53f86b9fd68a49b6b04..9a2a75dd183385915cebe9d1755c6c046586a833 100644 (file)
@@ -307,10 +307,11 @@ class BackupOptions(VDriveOptions):
     def opt_exclude_from(self, filepath):
         """Ignore file matching glob patterns listed in file, one per
         line. The file is assumed to be in the argv encoding."""
+        abs_filepath = argv_to_abspath(filepath)
         try:
-            exclude_file = file(filepath)
+            exclude_file = file(abs_filepath)
         except:
-            raise BackupConfigurationError('Error opening exclude file %r.' % filepath)
+            raise BackupConfigurationError('Error opening exclude file %s.' % quote_output(abs_filepath))
         try:
             for line in exclude_file:
                 self.opt_exclude(line)
index b3d899164f3ac07c06a9515be4a049a7852df173..be89e3524a445a435be875bc35b0e790485377e6 100644 (file)
@@ -5,6 +5,8 @@ from cStringIO import StringIO
 import urllib, re
 import simplejson
 
+from mock import patch
+
 from allmydata.util import fileutil, hashutil, base32
 from allmydata import uri
 from allmydata.immutable import upload
@@ -1867,6 +1869,22 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
         self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'),
                               (nice_doc,))
 
+    @patch('__builtin__.file')
+    def test_exclude_from_tilde_expansion(self, mock):
+        basedir = "cli/Backup/exclude_from_tilde_expansion"
+        fileutil.make_dirs(basedir)
+        nodeurl_path = os.path.join(basedir, 'node.url')
+        fileutil.write(nodeurl_path, 'http://example.net:2357/')
+
+        # ensure that tilde expansion is performed on exclude-from argument
+        exclude_file = u'~/.tahoe/excludes.dummy'
+        backup_options = cli.BackupOptions()
+
+        mock.return_value = StringIO()
+        backup_options.parseOptions(['--exclude-from', unicode_to_argv(exclude_file),
+                                     '--node-directory', basedir, 'from', 'to'])
+        self.failUnlessIn(((abspath_expanduser_unicode(exclude_file),), {}), mock.call_args_list)
+
     def test_ignore_symlinks(self):
         if not hasattr(os, 'symlink'):
             raise unittest.SkipTest("Symlinks are not supported by Python on this platform.")