Skip to content

Commit

Permalink
Fix #268: 修复改用shutil移动文件后可能导致文件被覆盖的问题
Browse files Browse the repository at this point in the history
Introduced in 37c2554

(cherry picked from commit 39133c5)
  • Loading branch information
Yuukiy committed Apr 5, 2024
1 parent 6ea05c4 commit 562ea70
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def rename_files(self):
def move_file(src:str, dst:str):
"""移动(重命名)文件并记录信息到日志"""
abs_dst = os.path.abspath(dst)
# shutil.move might overwrite dst file
if os.path.exists(abs_dst):
raise FileExistsError(f'File exists: {abs_dst}')
shutil.move(src, abs_dst)
src_rel = os.path.relpath(src)
dst_name = os.path.basename(dst)
Expand Down

0 comments on commit 562ea70

Please sign in to comment.