1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-29 11:16:43 +00:00

mount: only append archive id when needed

This commit is contained in:
Thomas Waldmann 2024-10-05 21:14:30 +02:00
parent 84245ef2bf
commit f624f76c13
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
2 changed files with 15 additions and 6 deletions

View file

@ -7,7 +7,7 @@
import sys
import tempfile
import time
from collections import defaultdict
from collections import defaultdict, Counter
from signal import SIGINT
from .constants import ROBJ_FILE_STREAM
@ -277,14 +277,19 @@ def __init__(self, manifest, args, decrypted_repository):
def _create_filesystem(self):
self._create_dir(parent=1) # first call, create root dir (inode == 1)
self.versions_index = FuseVersionsIndex()
for archive in self._manifest.archives.list_considering(self._args):
archives = self._manifest.archives.list_considering(self._args)
name_counter = Counter(a.name for a in archives)
duplicate_names = {a.name for a in archives if name_counter[a.name] > 1}
for archive in archives:
if self.versions:
# process archives immediately
self._process_archive(archive.id)
else:
# lazily load archives, create archive placeholder inode
archive_inode = self._create_dir(parent=1, mtime=int(archive.ts.timestamp() * 1e9))
name = f"{archive.name}-{bin_to_hex(archive.id):.8}" # archive names may be duplicate!
name = f"{archive.name}"
if name in duplicate_names:
name += f"-{bin_to_hex(archive.id):.8}"
self.contents[1][os.fsencode(name)] = archive_inode
self.pending_archives[archive_inode] = archive

View file

@ -204,14 +204,18 @@ def test_fuse_versions_view(archivers, request):
def test_fuse_duplicate_name(archivers, request):
archiver = request.getfixturevalue(archivers)
cmd(archiver, "repo-create", RK_ENCRYPTION)
cmd(archiver, "create", "archive", "input")
cmd(archiver, "create", "archive", "input")
cmd(archiver, "create", "duplicate", "input")
cmd(archiver, "create", "duplicate", "input")
cmd(archiver, "create", "unique1", "input")
cmd(archiver, "create", "unique2", "input")
mountpoint = os.path.join(archiver.tmpdir, "mountpoint")
# mount the whole repository, archives show up as toplevel directories:
with fuse_mount(archiver, mountpoint):
path = os.path.join(mountpoint)
dirs = os.listdir(path)
assert len(set(dirs)) == 2 # there must be 2 unique dir names for 2 archives
assert len(set(dirs)) == 4 # there must be 4 unique dir names for 4 archives
assert "unique1" in dirs # if an archive has a unique name, do not append the archive id
assert "unique2" in dirs
@pytest.mark.skipif(not llfuse, reason="llfuse not installed")