mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-01 12:09:10 +00:00
bandedstore: Handle aborted transactions better
This commit is contained in:
parent
2eea138c92
commit
af8c943694
2 changed files with 14 additions and 3 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
build
|
||||
*.pyc
|
||||
*.pyo
|
||||
|
|
@ -35,6 +35,10 @@ def _begin(self):
|
|||
self.state = self.OPEN
|
||||
self.band = None
|
||||
self.to_delete = set()
|
||||
band = self.next_band
|
||||
while os.path.exists(self.band_filename(band)):
|
||||
os.unlink(self.band_filename(band))
|
||||
band += 1
|
||||
|
||||
def create(self, path):
|
||||
os.mkdir(path)
|
||||
|
@ -84,18 +88,21 @@ def get(self, ns, id):
|
|||
else:
|
||||
raise self.DoesNotExist
|
||||
|
||||
def band_filename(self, band):
|
||||
return os.path.join(self.path, 'bands', str(band))
|
||||
|
||||
def retrieve_data(self, band, offset, size):
|
||||
with open(os.path.join(self.path, 'bands', str(band)), 'rb') as fd:
|
||||
with open(self.band_filename(band), 'rb') as fd:
|
||||
fd.seek(offset)
|
||||
return fd.read(size)
|
||||
|
||||
def store_data(self, data):
|
||||
if self.band is None:
|
||||
self.band = self.next_band
|
||||
assert not os.path.exists(os.path.join(self.path, 'bands', str(self.band)))
|
||||
assert not os.path.exists(self.band_filename(self.band))
|
||||
self.next_band += 1
|
||||
band = self.band
|
||||
with open(os.path.join(self.path, 'bands', str(band)), 'ab') as fd:
|
||||
with open(self.band_filename(band), 'ab') as fd:
|
||||
offset = fd.tell()
|
||||
fd.write(data)
|
||||
if offset + len(data) > self.BAND_LIMIT:
|
||||
|
|
Loading…
Reference in a new issue