lock repository when converting segments

This commit is contained in:
Antoine Beaupré 2015-10-01 09:35:17 -04:00
parent 58815bc28a
commit 98e4e6bc25
1 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,7 @@ from binascii import hexlify
import os
from .helpers import get_keys_dir
from .locking import UpgradableLock
from .repository import Repository, MAGIC
from .key import KeyfileKey, KeyfileNotFoundError
@ -22,7 +23,12 @@ class AtticRepositoryConverter(Repository):
else:
self.convert_keyfiles(keyfile, dryrun)
self.close()
# partial open: just hold on to the lock
self.lock = UpgradableLock(os.path.join(self.path, 'lock'),
exclusive=True).acquire()
self.convert_segments(segments, dryrun)
self.lock.release()
self.lock = None
self.convert_cache(dryrun)
@staticmethod
@ -34,6 +40,7 @@ class AtticRepositoryConverter(Repository):
luckily the magic string length didn't change so we can just
replace the 8 first bytes of all regular files in there."""
print("converting %d segments..." % len(segments))
for filename in segments:
print("converting segment %s in place" % filename)
if not dryrun: