mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 05:35:58 +00:00
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.
This commit is contained in:
parent
9108039786
commit
aee25c3564
1 changed files with 6 additions and 3 deletions
|
@ -858,10 +858,13 @@ def same_item(item, st):
|
||||||
st = os.stat(path, follow_symlinks=False)
|
st = os.stat(path, follow_symlinks=False)
|
||||||
if continue_extraction and same_item(item, st):
|
if continue_extraction and same_item(item, st):
|
||||||
return # done! we already have fully extracted this file in a previous run.
|
return # done! we already have fully extracted this file in a previous run.
|
||||||
elif stat.S_ISDIR(st.st_mode):
|
# remove anything that is not a directory
|
||||||
os.rmdir(path)
|
if not stat.S_ISDIR(st.st_mode):
|
||||||
else:
|
|
||||||
os.unlink(path)
|
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:
|
except UnicodeEncodeError:
|
||||||
raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding()) from None
|
raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding()) from None
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
Loading…
Reference in a new issue