mirror of https://github.com/borgbackup/borg.git
Initial (naive) full repository fuse mount support
This commit is contained in:
parent
a9fc62cc9a
commit
8e078b5f91
|
@ -245,12 +245,13 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
self.print_error('%s: Mountpoint must be a writable directory' % args.mountpoint)
|
self.print_error('%s: Mountpoint must be a writable directory' % args.mountpoint)
|
||||||
return self.exit_code
|
return self.exit_code
|
||||||
|
|
||||||
repository = self.open_repository(args.archive)
|
repository = self.open_repository(args.src)
|
||||||
manifest, key = Manifest.load(repository)
|
manifest, key = Manifest.load(repository)
|
||||||
self.print_verbose("Loading archive metadata...", newline=False)
|
if args.src.archive:
|
||||||
archive = Archive(repository, key, manifest, args.archive.archive)
|
archive = Archive(repository, key, manifest, args.src.archive)
|
||||||
self.print_verbose('done')
|
else:
|
||||||
operations = AtticOperations(key, repository, archive)
|
archive = None
|
||||||
|
operations = AtticOperations(key, repository, manifest, archive)
|
||||||
self.print_verbose("Mounting filesystem")
|
self.print_verbose("Mounting filesystem")
|
||||||
try:
|
try:
|
||||||
operations.mount(args.mountpoint, args.options, args.foreground)
|
operations.mount(args.mountpoint, args.options, args.foreground)
|
||||||
|
@ -562,8 +563,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
subparser = subparsers.add_parser('mount', parents=[common_parser],
|
subparser = subparsers.add_parser('mount', parents=[common_parser],
|
||||||
description=self.do_mount.__doc__)
|
description=self.do_mount.__doc__)
|
||||||
subparser.set_defaults(func=self.do_mount)
|
subparser.set_defaults(func=self.do_mount)
|
||||||
subparser.add_argument('archive', metavar='ARCHIVE', type=location_validator(archive=True),
|
subparser.add_argument('src', metavar='REPOSITORY_OR_ARCHIVE', type=location_validator(),
|
||||||
help='archive to mount')
|
help='repository/archive to mount')
|
||||||
subparser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str,
|
subparser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str,
|
||||||
help='where to mount filesystem')
|
help='where to mount filesystem')
|
||||||
subparser.add_argument('-f', '--foreground', dest='foreground',
|
subparser.add_argument('-f', '--foreground', dest='foreground',
|
||||||
|
|
|
@ -4,6 +4,7 @@ import llfuse
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
|
from attic.archive import Archive
|
||||||
|
|
||||||
from attic.helpers import daemonize
|
from attic.helpers import daemonize
|
||||||
# Does this version of llfuse support ns precision?
|
# Does this version of llfuse support ns precision?
|
||||||
|
@ -13,7 +14,7 @@ have_fuse_mtime_ns = hasattr(llfuse.EntryAttributes, 'st_mtime_ns')
|
||||||
class AtticOperations(llfuse.Operations):
|
class AtticOperations(llfuse.Operations):
|
||||||
"""Export Attic archive as a fuse filesystem
|
"""Export Attic archive as a fuse filesystem
|
||||||
"""
|
"""
|
||||||
def __init__(self, key, repository, archive):
|
def __init__(self, key, repository, manifest, archive):
|
||||||
super(AtticOperations, self).__init__()
|
super(AtticOperations, self).__init__()
|
||||||
self._inode_count = 0
|
self._inode_count = 0
|
||||||
self.key = key
|
self.key = key
|
||||||
|
@ -21,22 +22,31 @@ class AtticOperations(llfuse.Operations):
|
||||||
self.items = {}
|
self.items = {}
|
||||||
self.parent = {}
|
self.parent = {}
|
||||||
self.contents = defaultdict(dict)
|
self.contents = defaultdict(dict)
|
||||||
default_dir = {b'mode': 0o40755, b'mtime': int(time.time() * 1e9), b'uid': os.getuid(), b'gid': os.getgid()}
|
self.default_dir = {b'mode': 0o40755, b'mtime': int(time.time() * 1e9), b'uid': os.getuid(), b'gid': os.getgid()}
|
||||||
# Loop through all archive items and assign inode numbers and
|
if archive:
|
||||||
# extract hierarchy information
|
self.process_archive(archive)
|
||||||
|
else:
|
||||||
|
for archive_name in manifest.archives:
|
||||||
|
archive = Archive(repository, key, manifest, archive_name)
|
||||||
|
self.process_archive(archive, [os.fsencode(archive_name)])
|
||||||
|
|
||||||
|
def process_archive(self, archive, prefix=[]):
|
||||||
|
"""Build fuse inode hierarcy from archive metadata
|
||||||
|
"""
|
||||||
for item in archive.iter_items():
|
for item in archive.iter_items():
|
||||||
segments = os.fsencode(os.path.normpath(item[b'path'])).split(b'/')
|
segments = prefix + os.fsencode(os.path.normpath(item[b'path'])).split(b'/')
|
||||||
num_segments = len(segments)
|
num_segments = len(segments)
|
||||||
parent = 1
|
parent = 1
|
||||||
for i, segment in enumerate(segments, 1):
|
for i, segment in enumerate(segments, 1):
|
||||||
# Insert a default root inode if needed
|
# Insert a default root inode if needed
|
||||||
if self._inode_count == 0 and segment:
|
if self._inode_count == 0 and segment:
|
||||||
self.items[self.allocate_inode()] = default_dir
|
archive_inode = self.allocate_inode()
|
||||||
self.parent[1] = 1
|
self.items[archive_inode] = self.default_dir
|
||||||
|
self.parent[archive_inode] = parent
|
||||||
# Leaf segment?
|
# Leaf segment?
|
||||||
if i == num_segments:
|
if i == num_segments:
|
||||||
if b'source' in item and stat.S_ISREG(item[b'mode']):
|
if b'source' in item and stat.S_ISREG(item[b'mode']):
|
||||||
inode = self._find_inode(item[b'source'])
|
inode = self._find_inode(item[b'source'], prefix)
|
||||||
self.items[inode][b'nlink'] = self.items[inode].get(b'nlink', 1) + 1
|
self.items[inode][b'nlink'] = self.items[inode].get(b'nlink', 1) + 1
|
||||||
else:
|
else:
|
||||||
inode = self.allocate_inode()
|
inode = self.allocate_inode()
|
||||||
|
@ -48,7 +58,7 @@ class AtticOperations(llfuse.Operations):
|
||||||
parent = self.contents[parent][segment]
|
parent = self.contents[parent][segment]
|
||||||
else:
|
else:
|
||||||
inode = self.allocate_inode()
|
inode = self.allocate_inode()
|
||||||
self.items[inode] = default_dir
|
self.items[inode] = self.default_dir
|
||||||
self.parent[inode] = parent
|
self.parent[inode] = parent
|
||||||
if segment:
|
if segment:
|
||||||
self.contents[parent][segment] = inode
|
self.contents[parent][segment] = inode
|
||||||
|
@ -70,8 +80,8 @@ class AtticOperations(llfuse.Operations):
|
||||||
stat_.f_favail = 0
|
stat_.f_favail = 0
|
||||||
return stat_
|
return stat_
|
||||||
|
|
||||||
def _find_inode(self, path):
|
def _find_inode(self, path, prefix=[]):
|
||||||
segments = os.fsencode(os.path.normpath(path)).split(b'/')
|
segments = prefix + os.fsencode(os.path.normpath(path)).split(b'/')
|
||||||
inode = 1
|
inode = 1
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
inode = self.contents[inode][segment]
|
inode = self.contents[inode][segment]
|
||||||
|
|
|
@ -271,7 +271,29 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
||||||
self.assert_raises(SystemExit, lambda: self.attic('-h'))
|
self.assert_raises(SystemExit, lambda: self.attic('-h'))
|
||||||
|
|
||||||
@unittest.skipUnless(has_llfuse, 'llfuse not installed')
|
@unittest.skipUnless(has_llfuse, 'llfuse not installed')
|
||||||
def test_mount(self):
|
def test_fuse_mount_repository(self):
|
||||||
|
mountpoint = os.path.join(self.tmpdir, 'mountpoint')
|
||||||
|
os.mkdir(mountpoint)
|
||||||
|
self.attic('init', self.repository_location)
|
||||||
|
self.create_test_files()
|
||||||
|
self.attic('create', self.repository_location + '::archive', 'input')
|
||||||
|
self.attic('create', self.repository_location + '::archive2', 'input')
|
||||||
|
try:
|
||||||
|
self.attic('mount', self.repository_location, mountpoint, fork=True)
|
||||||
|
self.wait_for_mount(mountpoint)
|
||||||
|
self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive', 'input'))
|
||||||
|
self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive2', 'input'))
|
||||||
|
finally:
|
||||||
|
if sys.platform.startswith('linux'):
|
||||||
|
os.system('fusermount -u ' + mountpoint)
|
||||||
|
else:
|
||||||
|
os.system('umount ' + mountpoint)
|
||||||
|
os.rmdir(mountpoint)
|
||||||
|
# Give the daemon some time to exit
|
||||||
|
time.sleep(.2)
|
||||||
|
|
||||||
|
@unittest.skipUnless(has_llfuse, 'llfuse not installed')
|
||||||
|
def test_fuse_mount_archive(self):
|
||||||
mountpoint = os.path.join(self.tmpdir, 'mountpoint')
|
mountpoint = os.path.join(self.tmpdir, 'mountpoint')
|
||||||
os.mkdir(mountpoint)
|
os.mkdir(mountpoint)
|
||||||
self.attic('init', self.repository_location)
|
self.attic('init', self.repository_location)
|
||||||
|
|
Loading…
Reference in New Issue