mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-31 11:42:05 +00:00
Remove store commit race condition
This commit is contained in:
parent
bb6e4fbd93
commit
885dc88350
1 changed files with 6 additions and 2 deletions
|
@ -85,8 +85,9 @@ def read_dict(self, filename):
|
||||||
return msgpack.unpackb(fd.read())
|
return msgpack.unpackb(fd.read())
|
||||||
|
|
||||||
def write_dict(self, filename, d):
|
def write_dict(self, filename, d):
|
||||||
with open(filename, 'wb') as fd:
|
with open(filename+'.tmp', 'wb') as fd:
|
||||||
fd.write(msgpack.packb(d))
|
fd.write(msgpack.packb(d))
|
||||||
|
os.rename(filename+'.tmp', filename)
|
||||||
|
|
||||||
def delete_bands(self):
|
def delete_bands(self):
|
||||||
delete_path = os.path.join(self.path, 'delete')
|
delete_path = os.path.join(self.path, 'delete')
|
||||||
|
@ -95,7 +96,6 @@ def delete_bands(self):
|
||||||
for band in self.read_dict(delete_path):
|
for band in self.read_dict(delete_path):
|
||||||
assert bands.pop(band, 0) == 0
|
assert bands.pop(band, 0) == 0
|
||||||
self.io.delete_band(band, missing_ok=True)
|
self.io.delete_band(band, missing_ok=True)
|
||||||
os.unlink(delete_path)
|
|
||||||
self.write_dict(os.path.join(self.path, 'band'), bands)
|
self.write_dict(os.path.join(self.path, 'band'), bands)
|
||||||
|
|
||||||
def begin_txn(self):
|
def begin_txn(self):
|
||||||
|
@ -162,6 +162,10 @@ def rollback(self):
|
||||||
self.delete_bands()
|
self.delete_bands()
|
||||||
os.rename(os.path.join(self.path, 'txn.commit'),
|
os.rename(os.path.join(self.path, 'txn.commit'),
|
||||||
os.path.join(self.path, 'txn.tmp'))
|
os.path.join(self.path, 'txn.tmp'))
|
||||||
|
|
||||||
|
delete_path = os.path.join(self.path, 'delete')
|
||||||
|
if os.path.exists(delete_path):
|
||||||
|
os.unlink(delete_path)
|
||||||
# Roll back active transaction
|
# Roll back active transaction
|
||||||
txn_dir = os.path.join(self.path, 'txn.active')
|
txn_dir = os.path.join(self.path, 'txn.active')
|
||||||
if os.path.exists(txn_dir):
|
if os.path.exists(txn_dir):
|
||||||
|
|
Loading…
Reference in a new issue