From f4b12a3179891a7d1738f4dafcf67c7fff31dec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Tue, 23 Jul 2013 13:07:48 +0200 Subject: [PATCH] Added hard links support --- attic/fuse.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/attic/fuse.py b/attic/fuse.py index 1750aa595..8ab6f3b3c 100644 --- a/attic/fuse.py +++ b/attic/fuse.py @@ -2,11 +2,9 @@ import errno import llfuse import os +import stat import time -# TODO -# - multi archive -# hard links class AtticOperations(llfuse.Operations): """ @@ -22,7 +20,7 @@ def __init__(self, key, repository, archive): self.inode_contents = defaultdict(dict) for item, _ in archive.iter_items(): - head, tail = os.path.split(os.path.normpath(os.fsencode(item[b'path']))) + head, tail = os.path.split(os.fsencode(os.path.normpath(item[b'path']))) segments = head.split(b'/') parent = 1 for segment in segments: @@ -36,15 +34,24 @@ def __init__(self, key, repository, archive): parent = node.st_ino else: parent = self.inode_contents[parent][segment] - - node = self._make_item_inode(item) + if b'source' in item and stat.S_ISREG(item[b'mode']): + node = self._find_inode(item[b'source']) + else: + node = self._make_item_inode(item) + self.inodes[node.st_ino] = node + self.items[node.st_ino] = item node.st_nlink += 1 - self.inodes[node.st_ino] = node - self.items[node.st_ino] = item self.inode_parent[node.st_ino] = parent if tail: self.inode_contents[parent][tail] = node.st_ino + def _find_inode(self, path): + segments = os.fsencode(os.path.normpath(path)).split(b'/') + inode = 1 + for segment in segments: + inode = self.inode_contents[inode][segment] + return self.inodes[inode] + def _make_directory_inode(self): entry = llfuse.EntryAttributes() entry.st_ino = len(self.inodes) + 1