소스 검색

Added hard links support

Jonas Borgström 12 년 전
부모
커밋
f4b12a3179
1개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 15 8
      attic/fuse.py

+ 15 - 8
attic/fuse.py

@@ -2,11 +2,9 @@ from collections import defaultdict
 import errno
 import llfuse
 import os
+import stat
 import time
 
-# TODO
-# - multi archive
-# hard links
 
 class AtticOperations(llfuse.Operations):
     """
@@ -22,7 +20,7 @@ class AtticOperations(llfuse.Operations):
         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 @@ class AtticOperations(llfuse.Operations):
                     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