Skip to content

Commit 42e2c90

Browse files
committed
Don't remove file if it does not exist in sync_tree
This ensure better logs Part of IT-269
1 parent e61f84b commit 42e2c90

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/e3/fs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,12 @@ def safe_copy(src: FileInfo, dst: FileInfo) -> None:
792792

793793
try:
794794
if dst.basename != src.basename:
795-
rm(dst.path, glob=False)
795+
if dst.stat is not None:
796+
# Case in which the destination file exists but does
797+
# not have the same casing. In that case we delete the
798+
# target file and redo a copy. This occurs for example
799+
# on Windos with NTFS.
800+
rm(dst.path, glob=False)
796801
dst = FileInfo(
797802
os.path.join(os.path.dirname(dst.path), src.basename),
798803
None,
@@ -803,7 +808,8 @@ def safe_copy(src: FileInfo, dst: FileInfo) -> None:
803808
with open(dst.path, "wb") as fdst:
804809
shutil.copyfileobj(fsrc, fdst)
805810
except OSError:
806-
rm(dst.path, glob=False)
811+
if dst.stat is not None:
812+
rm(dst.path, glob=False)
807813
with open(src.path, "rb") as fsrc:
808814
with open(dst.path, "wb") as fdst:
809815
shutil.copyfileobj(fsrc, fdst)

0 commit comments

Comments
 (0)