فهرست منبع

borg upgrade - fix locking

because Repository.__init__ normally opens and locks the repo, and the upgrader just
inherited from (borg) Repository, it created a lock file there before the "backup copy"
was made.

No big problem, but a bit unclean.

Fixed it to not lock at the beginning, then make the copy, then lock.
Thomas Waldmann 10 سال پیش
والد
کامیت
7acda553ff
1فایلهای تغییر یافته به همراه6 افزوده شده و 2 حذف شده
  1. 6 2
      borg/upgrader.py

+ 6 - 2
borg/upgrader.py

@@ -16,6 +16,10 @@ ATTIC_MAGIC = b'ATTICSEG'
 
 
 class AtticRepositoryUpgrader(Repository):
+    def __init__(self, *args, **kw):
+        kw['lock'] = False  # do not create borg lock files (now) in attic repo
+        super().__init__(*args, **kw)
+
     def upgrade(self, dryrun=True, inplace=False):
         """convert an attic repository to a borg repository
 
@@ -34,8 +38,8 @@ class AtticRepositoryUpgrader(Repository):
             if not dryrun:
                 shutil.copytree(self.path, backup, copy_function=os.link)
         logger.info("opening attic repository with borg and converting")
-        # we need to open the repo to load configuration, keyfiles and segments
-        self.open(self.path, exclusive=False)
+        # now lock the repo, after we have made the copy
+        self.lock = UpgradableLock(os.path.join(self.path, 'lock'), exclusive=True, timeout=1.0).acquire()
         segments = [filename for i, filename in self.io.segment_iterator()]
         try:
             keyfile = self.find_attic_keyfile()