Skip to content

Commit 7ba1fb8

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 75f8391 commit 7ba1fb8

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
@@ -853,10 +853,13 @@ def same_item(item, st):
853853
st = os.stat(path, follow_symlinks=False)
854854
if continue_extraction and same_item(item, st):
855855
return # done! we already have fully extracted this file in a previous run.
856-
elif stat.S_ISDIR(st.st_mode):
857-
os.rmdir(path)
858-
else:
856+
# remove anything that is not a directory
857+
if not stat.S_ISDIR(st.st_mode):
859858
os.unlink(path)
859+
# only remove a directory if it is conflicting
860+
# preserve existing directories because they might be subvolumes
861+
elif not stat.S_ISDIR(item.mode):
862+
os.rmdir(path)
860863
except UnicodeEncodeError:
861864
raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding()) from None
862865
except OSError:

0 commit comments

Comments
 (0)