tahoe backup: perform tilde expansion in exclude-from filename (version 2). fixes #1241

This commit is contained in:
david-sarah 2010-10-30 20:52:31 -07:00
parent 99a6e63814
commit 6eaa7f2356
2 changed files with 21 additions and 2 deletions

View 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)

View 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.")