1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 17:27:31 +00:00

Merge pull request #1558 from ThomasWaldmann/improve-fuse

Improve fuse
This commit is contained in:
enkore 2016-09-01 21:49:10 +02:00 committed by GitHub
commit d3cea7018c

View file

@ -140,29 +140,23 @@ def process_archive(self, archive, prefix=[]):
for item in unpacker: for item in unpacker:
item = Item(internal_dict=item) item = Item(internal_dict=item)
is_dir = stat.S_ISDIR(item.mode) is_dir = stat.S_ISDIR(item.mode)
try: if is_dir:
# This can happen if an archive was created with a command line like try:
# $ borg create ... dir1/file dir1 # This can happen if an archive was created with a command line like
# In this case the code below will have created a default_dir inode for dir1 already. # $ borg create ... dir1/file dir1
path = safe_encode(item.path) # In this case the code below will have created a default_dir inode for dir1 already.
if not is_dir: inode = self._find_inode(item.path, prefix)
# not a directory -> no lookup needed except KeyError:
raise KeyError pass
inode = self._find_inode(path, prefix) else:
except KeyError: self.items[inode] = item
pass continue
else:
self.items[inode] = item
continue
segments = prefix + os.fsencode(os.path.normpath(item.path)).split(b'/') segments = prefix + os.fsencode(os.path.normpath(item.path)).split(b'/')
del item.path del item.path
num_segments = len(segments)
parent = 1 parent = 1
for i, segment in enumerate(segments, 1): for segment in segments[:-1]:
if i == num_segments: parent = self.process_inner(segment, parent)
self.process_leaf(segment, item, parent, prefix, is_dir) self.process_leaf(segments[-1], item, parent, prefix, is_dir)
else:
parent = self.process_inner(segment, parent)
def process_leaf(self, name, item, parent, prefix, is_dir): def process_leaf(self, name, item, parent, prefix, is_dir):
def version_name(name, item): def version_name(name, item):
@ -176,9 +170,7 @@ def version_name(name, item):
if self.versions and not is_dir: if self.versions and not is_dir:
parent = self.process_inner(name, parent) parent = self.process_inner(name, parent)
name = version_name(name, item) name = version_name(name, item)
self.process_real_leaf(name, item, parent, prefix)
def process_real_leaf(self, name, item, parent, prefix):
if 'source' in item and stat.S_ISREG(item.mode): if 'source' in item and stat.S_ISREG(item.mode):
inode = self._find_inode(item.source, prefix) inode = self._find_inode(item.source, prefix)
item = self.cache.get(inode) item = self.cache.get(inode)
@ -190,15 +182,15 @@ def process_real_leaf(self, name, item, parent, prefix):
if name: if name:
self.contents[parent][name] = inode self.contents[parent][name] = inode
def process_inner(self, name, parent): def process_inner(self, name, parent_inode):
if name in self.contents[parent]: dir = self.contents[parent_inode]
parent = self.contents[parent][name] if name in dir:
inode = dir[name]
else: else:
inode = self._create_dir(parent) inode = self._create_dir(parent_inode)
if name: if name:
self.contents[parent][name] = inode dir[name] = inode
parent = inode return inode
return parent
def allocate_inode(self): def allocate_inode(self):
self._inode_count += 1 self._inode_count += 1