Skip to content

repository: two minor improvements #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions attic/repository.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ def report_error(msg):
report_error('Adding commit tag to segment {}'.format(transaction_id))
self.io.segment = transaction_id + 1
self.io.write_commit()
self.io.close_segment()
if current_index and not repair:
if len(current_index) != len(self.index):
report_error('Index object count mismatch. {} != {}'.format(len(current_index), len(self.index)))
Expand Down Expand Up @@ -478,6 +477,9 @@ def get_fd(self, segment):
return fd

def delete_segment(self, segment):
fd = self.fds.pop(segment)
if fd is not None:
fd.close()
try:
os.unlink(self.segment_filename(segment))
except OSError:
Expand Down Expand Up @@ -513,7 +515,9 @@ def iter_objects(self, segment, include_data=False):
header = fd.read(self.header_fmt.size)

def recover_segment(self, segment, filename):
self.fds.pop(segment).close()
fd = self.fds.pop(segment)
if fd is not None:
fd.close()
# FIXME: save a copy of the original file
with open(filename, 'rb') as fd:
data = memoryview(fd.read())
Expand Down