浏览代码

Merge pull request #7265 from ThomasWaldmann/fix-locking-1.2

Fix locking (1.2-maint)
TW 2 年之前
父节点
当前提交
48713ebff6
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 2 2
      src/borg/locking.py
  2. 4 1
      src/borg/testsuite/locking.py

+ 2 - 2
src/borg/locking.py

@@ -139,7 +139,7 @@ class ExclusiveLock:
             timer = TimeoutTimer(timeout, sleep).start()
             while True:
                 try:
-                    os.rename(temp_path, self.path)
+                    os.replace(temp_path, self.path)
                 except OSError:  # already locked
                     if self.by_me():
                         return self
@@ -195,7 +195,7 @@ class ExclusiveLock:
                     host_pid, thread_str = name.rsplit('-', 1)
                     host, pid_str = host_pid.rsplit('.', 1)
                     pid = int(pid_str)
-                    thread = int(thread_str)
+                    thread = int(thread_str, 16)
                 except ValueError:
                     # Malformed lock name? Or just some new format we don't understand?
                     logger.error("Found malformed lock %s in %s. Please check/fix manually.", name, self.path)

+ 4 - 1
src/borg/testsuite/locking.py

@@ -157,8 +157,11 @@ class TestExclusiveLock:
         exception_counter = SynchronizedCounter()
         print_lock = ThreadingLock()
         thread = None
+        host_id, process_id = "differenthost", 1234
         for thread_id in range(RACE_TEST_NUM_THREADS):
-            thread = Thread(target=acquire_release_loop, args=(('foo', thread_id, 0), RACE_TEST_DURATION, thread_id, lock_owner_counter, exception_counter, print_lock, thread))
+            thread = Thread(target=acquire_release_loop,
+                            args=((host_id, process_id, thread_id), RACE_TEST_DURATION, thread_id,
+                                  lock_owner_counter, exception_counter, print_lock, thread))
             thread.start()
         thread.join()  # joining the last thread