Browse Source

Adding 'open' function

Lertsenem 5 years ago
parent
commit
6971dab7fe
1 changed files with 19 additions and 2 deletions
  1. 19 2
      tagfs/tagfs.py

+ 19 - 2
tagfs/tagfs.py

@@ -257,10 +257,27 @@ class TagFS(fuse.Operations):
257 257
 
258 258
 
259 259
     # File
260
-
260
+    # -------------------------------------------------------------------------
261 261
     def open(self, path, flags):
262 262
         logging.debug("open")
263
-        return os.open(self._fullpath(path), flags)
263
+
264
+        currtags = self._path2tags(path)
265
+        files    = self.index.tags2files(currtags)
266
+
267
+        if len(files) > 1:
268
+            raise IsADirectoryError("Is a directory: '{}'".format(path))
269
+
270
+        if len(files) == 0:
271
+            raise FileNotFoundError(
272
+                    "No such file or directory: '{}'" \
273
+                            .format(path)
274
+                                   )
275
+        
276
+        if len(files) == 1:
277
+            my_file_id   = files.pop()
278
+            my_file_real = self._realfile(my_file_id)
279
+
280
+            return os.open(my_file_real, flags)
264 281
 
265 282
     def create(self, path, mode, fi=None):
266 283
         logging.debug("create")