From 6eaa7f2356881f16594dab93a41cc62e03431561 Mon Sep 17 00:00:00 2001 From: david-sarah <david-sarah@jacaranda.org> Date: Sat, 30 Oct 2010 20:52:31 -0700 Subject: [PATCH] tahoe backup: perform tilde expansion in exclude-from filename (version 2). fixes #1241 --- src/allmydata/scripts/cli.py | 5 +++-- src/allmydata/test/test_cli.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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.") -- 2.45.2