Thomas Waldmann 2 недель назад
Родитель
Сommit
c9ebeba933
3 измененных файлов с 27 добавлено и 9 удалено
  1. 9 1
      src/borg/fuse.py
  2. 10 6
      src/borg/fuse_impl.py
  3. 8 2
      src/borg/hlfuse.py

+ 9 - 1
src/borg/fuse.py

@@ -9,11 +9,19 @@ import tempfile
 import time
 from collections import defaultdict, Counter
 from signal import SIGINT
+from typing import TYPE_CHECKING
 
 from .constants import ROBJ_FILE_STREAM, zeros
-from .fuse_impl import llfuse, has_pyfuse3
 from .platform import ENOATTR
 
+if TYPE_CHECKING:
+    # For type checking, assume llfuse is available
+    # This allows mypy to understand llfuse.Operations
+    import llfuse
+    from .fuse_impl import has_pyfuse3
+else:
+    from .fuse_impl import llfuse, has_pyfuse3
+
 if has_pyfuse3:
     import trio
 

+ 10 - 6
src/borg/fuse_impl.py

@@ -3,19 +3,24 @@ Loads the library for the FUSE implementation.
 """
 
 import os
+import types
 
 from .platform import ENOATTR  # noqa
 
 BORG_FUSE_IMPL = os.environ.get("BORG_FUSE_IMPL", "mfusepy,pyfuse3,llfuse")
 
+hlfuse: types.ModuleType | None = None
+llfuse: types.ModuleType | None = None
+
 for FUSE_IMPL in BORG_FUSE_IMPL.split(","):
     FUSE_IMPL = FUSE_IMPL.strip()
     if FUSE_IMPL == "pyfuse3":
         try:
-            import pyfuse3 as llfuse
+            import pyfuse3
         except ImportError:
             pass
         else:
+            llfuse = pyfuse3
             has_llfuse = False
             has_pyfuse3 = True
             has_mfusepy = False
@@ -24,10 +29,11 @@ for FUSE_IMPL in BORG_FUSE_IMPL.split(","):
             break
     elif FUSE_IMPL == "llfuse":
         try:
-            import llfuse
+            import llfuse as llfuse_module
         except ImportError:
             pass
         else:
+            llfuse = llfuse_module
             has_llfuse = True
             has_pyfuse3 = False
             has_mfusepy = False
@@ -36,11 +42,11 @@ for FUSE_IMPL in BORG_FUSE_IMPL.split(","):
             break
     elif FUSE_IMPL == "mfusepy":
         try:
-            import mfusepy as hlfuse
+            import mfusepy
         except ImportError:
             pass
         else:
-            llfuse = None  # noqa
+            hlfuse = mfusepy
             has_llfuse = False
             has_pyfuse3 = False
             has_mfusepy = True
@@ -51,8 +57,6 @@ for FUSE_IMPL in BORG_FUSE_IMPL.split(","):
     else:
         raise RuntimeError("Unknown FUSE implementation in BORG_FUSE_IMPL: '%s'." % BORG_FUSE_IMPL)
 else:
-    llfuse = None  # noqa
-    hlfuse = None  # noqa
     has_llfuse = False
     has_pyfuse3 = False
     has_mfusepy = False

+ 8 - 2
src/borg/hlfuse.py

@@ -5,10 +5,16 @@ import os
 import stat
 import time
 from collections import Counter
+from typing import TYPE_CHECKING
 
 from .constants import ROBJ_FILE_STREAM, zeros, ROBJ_DONTCARE
 
-from .fuse_impl import hlfuse
+if TYPE_CHECKING:
+    # For type checking, assume mfusepy is available
+    # This allows mypy to understand hlfuse.Operations
+    import mfusepy as hlfuse
+else:
+    from .fuse_impl import hlfuse
 
 from .logger import create_logger
 
@@ -28,7 +34,7 @@ from .repository import Repository
 from .remote import RemoteRepository
 
 BLOCK_SIZE = 512  # Standard filesystem block size for st_blocks and statfs
-DEBUG_LOG = None  # os.path.join(os.getcwd(), "fuse_debug.log")
+DEBUG_LOG: str | None = None  # os.path.join(os.getcwd(), "fuse_debug.log")
 
 
 def debug_log(msg):