Преглед изворни кода

fuse/mount code and test fixes

Thomas Waldmann пре 9 месеци
родитељ
комит
cb9ff3b490

+ 2 - 2
src/borg/fuse.py

@@ -46,7 +46,7 @@ from .helpers.lrucache import LRUCache
 from .item import Item
 from .platform import uid2user, gid2group
 from .platformflags import is_darwin
-from .remote import RemoteRepository  # TODO 3
+from .remote3 import RemoteRepository3
 
 
 def fuse_main():
@@ -546,7 +546,7 @@ class FuseOperations(llfuse.Operations, FuseBackend):
         self._create_filesystem()
         llfuse.init(self, mountpoint, options)
         if not foreground:
-            if isinstance(self.repository_uncached, RemoteRepository):
+            if isinstance(self.repository_uncached, RemoteRepository3):
                 daemonize()
             else:
                 with daemonizing() as (old_id, new_id):

+ 5 - 0
src/borg/repository3.py

@@ -379,6 +379,11 @@ class Repository3:
     def break_lock(self):
         Lock(self.store).break_lock()
 
+    def migrate_lock(self, old_id, new_id):
+        # note: only needed for local repos
+        if self.lock is not None:
+            self.lock.migrate_lock(old_id, new_id)
+
     def get_manifest(self):
         try:
             return self.store.load("config/manifest")

+ 1 - 1
src/borg/testsuite/archiver/mount_cmds.py

@@ -7,7 +7,7 @@ import pytest
 
 from ... import xattr, platform
 from ...constants import *  # NOQA
-from ...locking import Lock
+from ...locking3 import Lock
 from ...helpers import flags_noatime, flags_normal
 from .. import has_lchflags, llfuse
 from .. import changedir, no_selinux, same_ts_ns

+ 14 - 0
src/borg/testsuite/locking3.py

@@ -84,3 +84,17 @@ class TestLock:
         assert len(lock_keys_b00) == 1
         assert len(lock_keys_b21) == 0  # stale lock was ignored
         assert len(list(lock.store.list("locks"))) == 0  # stale lock was removed from store
+
+    def test_migrate_lock(self, lockstore):
+        old_id, new_id = ID1, ID2
+        assert old_id[1] != new_id[1]  # different PIDs (like when doing daemonize())
+        lock = Lock(lockstore, id=old_id).acquire()
+        old_locks = lock._find_locks(only_mine=True)
+        assert lock.id == old_id  # lock is for old id / PID
+        lock.migrate_lock(old_id, new_id)  # fix the lock
+        assert lock.id == new_id  # lock corresponds to the new id / PID
+        new_locks = lock._find_locks(only_mine=True)
+        assert old_locks != new_locks
+        assert len(old_locks) == len(new_locks) == 1
+        assert old_locks[0]["hostid"] == old_id[0]
+        assert new_locks[0]["hostid"] == new_id[0]