1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 09:47:58 +00:00

Merge pull request #1833 from enkore/issue/1821

borg init: fix free space check crashing if disk is full
This commit is contained in:
enkore 2016-11-12 01:23:34 +01:00 committed by GitHub
commit 80b86709ef
2 changed files with 14 additions and 1 deletions

View file

@ -120,6 +120,7 @@ def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=Tru
self.lock_wait = lock_wait
self.do_lock = lock
self.do_create = create
self.created = False
self.exclusive = exclusive
self.append_only = append_only
self.hostname_is_unique = yes(env_var_override='BORG_HOSTNAME_IS_UNIQUE', env_msg=None, prompt=False)
@ -138,6 +139,7 @@ def __enter__(self):
if self.do_create:
self.do_create = False
self.create(self.path)
self.created = True
self.open(self.path, bool(self.exclusive), lock_wait=self.lock_wait, lock=self.do_lock)
return self
@ -437,7 +439,11 @@ def check_free_space(self):
free_space = st_vfs.f_bavail * st_vfs.f_bsize
logger.debug('check_free_space: required bytes {}, free bytes {}'.format(required_free_space, free_space))
if free_space < required_free_space:
self._rollback(cleanup=True)
if self.created:
logger.error('Not enough free space to initialize repository at this location.')
self.destroy()
else:
self._rollback(cleanup=True)
formatted_required = format_file_size(required_free_space)
formatted_free = format_file_size(free_space)
raise self.InsufficientFreeSpaceError(formatted_required, formatted_free)

View file

@ -406,6 +406,13 @@ def test_additional_free_space(self):
self.repository.put(H(0), b'foobar')
with pytest.raises(Repository.InsufficientFreeSpaceError):
self.repository.commit()
assert os.path.exists(self.repository.path)
def test_create_free_space(self):
self.repository.additional_free_space = 1e20
with pytest.raises(Repository.InsufficientFreeSpaceError):
self.add_keys()
assert not os.path.exists(self.repository.path)
class NonceReservation(RepositoryTestCaseBase):