From 4cb3355d9051d42046fab88bfa4b2e570e1cefc3 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Thu, 8 Sep 2016 16:39:44 +0200 Subject: [PATCH] create --read-special fix crash on broken symlink also correctly processes broken symlinks. before this regressed to a crash (5b45385) a broken symlink would've been skipped. --- borg/archiver.py | 9 +++++++-- borg/testsuite/archiver.py | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 7605fcd92..785a7b8d1 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -306,8 +306,13 @@ class Archiver: if not read_special: status = archive.process_symlink(path, st) else: - st_target = os.stat(path) - if is_special(st_target.st_mode): + try: + 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) else: status = archive.process_symlink(path, st) diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index f563ea428..7b2193595 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -901,6 +901,14 @@ class ArchiverTestCase(ArchiverTestCaseBase): output = self.cmd('create', '-v', '--list', '--filter=AM', self.repository_location + '::test3', 'input') 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): # self.create_regular_file('file1', size=1024 * 80) # self.cmd('init', self.repository_location)