Skip to content

Commit

Permalink
extract_item: do not delete an existing directory if possible
Browse files Browse the repository at this point in the history
A pre-existing directory might be a Btrfs subvolume that was created by
the user ahead of time when restoring several nested subvolumes from a
single archive.
  • Loading branch information
intelfx committed Oct 10, 2023
1 parent 75f8391 commit 7ba1fb8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,13 @@ def same_item(item, st):
st = os.stat(path, follow_symlinks=False)
if continue_extraction and same_item(item, st):
return # done! we already have fully extracted this file in a previous run.
elif stat.S_ISDIR(st.st_mode):
os.rmdir(path)
else:
# remove anything that is not a directory
if not stat.S_ISDIR(st.st_mode):
os.unlink(path)
# only remove a directory if it is conflicting
# preserve existing directories because they might be subvolumes
elif not stat.S_ISDIR(item.mode):
os.rmdir(path)
except UnicodeEncodeError:
raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding()) from None
except OSError:
Expand Down

0 comments on commit 7ba1fb8

Please # to comment.