1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 02:08:54 +00:00

Merge pull request #1585 from enkore/issue/1584

create --read-special fix crash on broken symlink
This commit is contained in:
enkore 2016-09-08 23:53:51 +02:00 committed by GitHub
commit 142079f3cb
3 changed files with 17 additions and 3 deletions

View file

@ -610,7 +610,8 @@ def process_dev(self, path, st):
return 'b' # block device return 'b' # block device
def process_symlink(self, path, st): def process_symlink(self, path, st):
source = os.readlink(path) with backup_io():
source = os.readlink(path)
item = {b'path': make_path_safe(path), b'source': source} item = {b'path': make_path_safe(path), b'source': source}
item.update(self.stat_attrs(st, path)) item.update(self.stat_attrs(st, path))
self.add_item(item) self.add_item(item)

View file

@ -306,8 +306,13 @@ def _process(self, archive, cache, matcher, exclude_caches, exclude_if_present,
if not read_special: if not read_special:
status = archive.process_symlink(path, st) status = archive.process_symlink(path, st)
else: else:
st_target = os.stat(path) try:
if is_special(st_target.st_mode): st_target = os.stat(path)
except OSError:
special = False
else:
special = is_special(st_target.st_mode)
if special:
status = archive.process_file(path, st_target, cache) status = archive.process_file(path, st_target, cache)
else: else:
status = archive.process_symlink(path, st) status = archive.process_symlink(path, st)

View file

@ -901,6 +901,14 @@ def test_create_topical(self):
output = self.cmd('create', '-v', '--list', '--filter=AM', self.repository_location + '::test3', 'input') output = self.cmd('create', '-v', '--list', '--filter=AM', self.repository_location + '::test3', 'input')
self.assert_in('file1', output) self.assert_in('file1', output)
def test_create_read_special_broken_symlink(self):
os.symlink('somewhere doesnt exist', os.path.join(self.input_path, 'link'))
self.cmd('init', self.repository_location)
archive = self.repository_location + '::test'
self.cmd('create', '--read-special', archive, 'input')
output = self.cmd('list', archive)
assert 'input/link -> somewhere doesnt exist' in output
# def test_cmdline_compatibility(self): # def test_cmdline_compatibility(self):
# self.create_regular_file('file1', size=1024 * 80) # self.create_regular_file('file1', size=1024 * 80)
# self.cmd('init', self.repository_location) # self.cmd('init', self.repository_location)