mirror of https://github.com/borgbackup/borg.git
RepositoryCache: truncate+unlink errored file
This commit is contained in:
parent
de00d9d822
commit
f786211b12
|
@ -27,6 +27,7 @@ from .helpers import hostname_is_unique
|
|||
from .helpers import replace_placeholders
|
||||
from .helpers import sysinfo
|
||||
from .helpers import format_file_size
|
||||
from .helpers import truncate_and_unlink
|
||||
from .logger import create_logger, setup_logging
|
||||
from .repository import Repository, MAX_OBJECT_SIZE, LIST_SCAN_LIMIT
|
||||
from .version import parse_version, format_version
|
||||
|
@ -1144,6 +1145,10 @@ class RepositoryCache(RepositoryNoCache):
|
|||
with open(file, 'wb') as fd:
|
||||
fd.write(packed)
|
||||
except OSError as os_error:
|
||||
try:
|
||||
truncate_and_unlink(file)
|
||||
except FileNotFoundError:
|
||||
pass # open() could have failed as well
|
||||
if os_error.errno == errno.ENOSPC:
|
||||
self.enospc += 1
|
||||
self.backoff()
|
||||
|
|
|
@ -141,6 +141,9 @@ class TestRepositoryCache:
|
|||
def write(self, data):
|
||||
raise OSError(errno.ENOSPC, 'foo')
|
||||
|
||||
def truncate(self, n=None):
|
||||
pass
|
||||
|
||||
iterator = cache.get_many([H(1), H(2), H(3)])
|
||||
assert next(iterator) == b'1234'
|
||||
|
||||
|
|
Loading…
Reference in New Issue