diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..898aef0f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +*.pyc +*.pyo + diff --git a/dedupestore/bandstore.py b/dedupestore/bandstore.py index e28eb65bb..b42c36cca 100644 --- a/dedupestore/bandstore.py +++ b/dedupestore/bandstore.py @@ -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: