1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-12 07:08:47 +00:00

FilesystemObjectProcessors.process_file: clean up orphaned chunks in case of exceptions

Note: no changes inside the indented block,
just added the try and the except block.
This commit is contained in:
Thomas Waldmann 2023-02-12 20:04:08 +01:00
parent f1981715e4
commit d0c61bbbf1
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -1451,6 +1451,9 @@ class FilesystemObjectProcessors:
# so it can be extracted / accessed in FUSE mount like a regular file. # so it can be extracted / accessed in FUSE mount like a regular file.
# this needs to be done early, so that part files also get the patched mode. # this needs to be done early, so that part files also get the patched mode.
item.mode = stat.S_IFREG | stat.S_IMODE(item.mode) item.mode = stat.S_IFREG | stat.S_IMODE(item.mode)
# we begin processing chunks now (writing or incref'ing them to the repository),
# which might require cleanup (see except-branch):
try:
if hl_chunks is not None: # create_helper gave us chunks from a previous hardlink if hl_chunks is not None: # create_helper gave us chunks from a previous hardlink
item.chunks = [] item.chunks = []
for chunk_id, chunk_size in hl_chunks: for chunk_id, chunk_size in hl_chunks:
@ -1510,7 +1513,8 @@ class FilesystemObjectProcessors:
# - blk/chr devices don't change ctime anyway. # - blk/chr devices don't change ctime anyway.
changed_while_backup = not is_special_file and st.st_ctime_ns != st2.st_ctime_ns changed_while_backup = not is_special_file and st.st_ctime_ns != st2.st_ctime_ns
if changed_while_backup: if changed_while_backup:
status = "C" # regular file changed while we backed it up, might be inconsistent/corrupt! # regular file changed while we backed it up, might be inconsistent/corrupt!
status = "C"
if not is_special_file and not changed_while_backup: if not is_special_file and not changed_while_backup:
# we must not memorize special files, because the contents of e.g. a # we must not memorize special files, because the contents of e.g. a
# block or char device will change without its mtime/size/inode changing. # block or char device will change without its mtime/size/inode changing.
@ -1521,6 +1525,16 @@ class FilesystemObjectProcessors:
item.update(self.metadata_collector.stat_ext_attrs(st, path, fd=fd)) item.update(self.metadata_collector.stat_ext_attrs(st, path, fd=fd))
item.get_size(memorize=True) item.get_size(memorize=True)
return status return status
except BackupOSError:
# Something went wrong and we might need to clean up a bit.
# Maybe we have already incref'ed some file content chunks in the repo -
# but we will not add an item (see add_item in create_helper) and thus
# they would be orphaned chunks in case that we commit the transaction.
for chunk in item.get("chunks", []):
cache.chunk_decref(chunk.id, self.stats, wait=False)
# Now that we have cleaned up the chunk references, we can re-raise the exception.
# This will skip processing of this file, but might retry or continue with the next one.
raise
class TarfileObjectProcessors: class TarfileObjectProcessors: