Skip to content

Commit aee25c3

Browse files
committed
extract_item: do not delete an existing directory if possible
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.
1 parent 9108039 commit aee25c3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/borg/archive.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,13 @@ def same_item(item, st):
858858
st = os.stat(path, follow_symlinks=False)
859859
if continue_extraction and same_item(item, st):
860860
return # done! we already have fully extracted this file in a previous run.
861-
elif stat.S_ISDIR(st.st_mode):
862-
os.rmdir(path)
863-
else:
861+
# remove anything that is not a directory
862+
if not stat.S_ISDIR(st.st_mode):
864863
os.unlink(path)
864+
# only remove a directory if it is conflicting
865+
# preserve existing directories because they might be subvolumes
866+
elif not stat.S_ISDIR(item.mode):
867+
os.rmdir(path)
865868
except UnicodeEncodeError:
866869
raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding()) from None
867870
except OSError:

0 commit comments

Comments
 (0)