mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-08 16:23:42 -04:00
Merge pull request #9610 from ThomasWaldmann/slashdot-root-1.4
Some checks are pending
CI / lint (push) Waiting to run
CI / asan_ubsan (push) Blocked by required conditions
CI / native_tests (push) Blocked by required conditions
CI / vm_tests (Haiku, false, haiku, r1beta5) (push) Blocked by required conditions
CI / vm_tests (NetBSD, false, netbsd, 10.1) (push) Blocked by required conditions
CI / vm_tests (OpenBSD, false, openbsd, 7.7) (push) Blocked by required conditions
CI / vm_tests (borg-freebsd-14-x86_64-gh, FreeBSD, true, freebsd, 14.3) (push) Blocked by required conditions
CodeQL / Analyze (push) Waiting to run
Windows CI / msys2-ucrt64 (push) Waiting to run
Some checks are pending
CI / lint (push) Waiting to run
CI / asan_ubsan (push) Blocked by required conditions
CI / native_tests (push) Blocked by required conditions
CI / vm_tests (Haiku, false, haiku, r1beta5) (push) Blocked by required conditions
CI / vm_tests (NetBSD, false, netbsd, 10.1) (push) Blocked by required conditions
CI / vm_tests (OpenBSD, false, openbsd, 7.7) (push) Blocked by required conditions
CI / vm_tests (borg-freebsd-14-x86_64-gh, FreeBSD, true, freebsd, 14.3) (push) Blocked by required conditions
CodeQL / Analyze (push) Waiting to run
Windows CI / msys2-ucrt64 (push) Waiting to run
Fix slashdot hack excluding source directory metadata, fixes #9534
This commit is contained in:
commit
1d420a9a61
2 changed files with 25 additions and 3 deletions
|
|
@ -1353,12 +1353,16 @@ class FilesystemObjectProcessors:
|
|||
def create_helper(self, path, st, status=None, hardlinkable=True, strip_prefix=None):
|
||||
if strip_prefix is not None:
|
||||
assert not path.endswith(os.sep)
|
||||
if strip_prefix.startswith(path + os.sep):
|
||||
if path + os.sep == strip_prefix:
|
||||
# this is the directory the slashdot hack points to - archive it as the root.
|
||||
path = "."
|
||||
elif strip_prefix.startswith(path + os.sep):
|
||||
# still on a directory level that shall be stripped - do not create an item for this!
|
||||
yield None, 'x', False, False
|
||||
return
|
||||
# adjust path, remove stripped directory levels
|
||||
path = path.removeprefix(strip_prefix)
|
||||
else:
|
||||
# adjust path, remove stripped directory levels
|
||||
path = path.removeprefix(strip_prefix)
|
||||
|
||||
safe_path = make_path_safe(path)
|
||||
item = Item(path=safe_path)
|
||||
|
|
|
|||
|
|
@ -2297,6 +2297,24 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
|||
assert 'secondB' in output
|
||||
assert 'secondB/thirdB' in output
|
||||
|
||||
def test_create_dotslash_hack_root_metadata(self):
|
||||
"""Test that the slashdot hack archives the source directory metadata as the archive root."""
|
||||
os.makedirs(os.path.join(self.input_path, "first", "subdir"))
|
||||
self.create_regular_file("first/file1", contents=b"hello")
|
||||
self.cmd('init', '--encryption=none', self.repository_location)
|
||||
archive = self.repository_location + '::test'
|
||||
self.cmd('create', archive, 'input/first/./') # slashdot hack
|
||||
output = self.cmd('list', archive)
|
||||
# the root directory "." must be in the archive (this was the bug in #9534).
|
||||
lines = output.splitlines()
|
||||
assert lines[0].endswith(" .")
|
||||
# children of the slashdot target must be archived.
|
||||
assert "subdir" in output
|
||||
assert "file1" in output
|
||||
# parent directories must NOT be in the archive.
|
||||
assert "input" not in output
|
||||
assert "first" not in output
|
||||
|
||||
# def test_cmdline_compatibility(self):
|
||||
# self.create_regular_file('file1', size=1024 * 80)
|
||||
# self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||
|
|
|
|||
Loading…
Reference in a new issue