From: david-sarah Date: Sun, 31 Oct 2010 03:52:31 +0000 (-0700) Subject: tahoe backup: perform tilde expansion in exclude-from filename (version 2). fixes... X-Git-Tag: trac-4800~13 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/simplejson/statistics?a=commitdiff_plain;h=6eaa7f2356881f16594dab93a41cc62e03431561;p=tahoe-lafs%2Ftahoe-lafs.git tahoe backup: perform tilde expansion in exclude-from filename (version 2). fixes #1241 --- diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index bb0f4db2..9a2a75dd 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -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) diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index b3d89916..be89e352 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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.")