From ef3a5bccac42d267b5bc500c872efac5becdc61c Mon Sep 17 00:00:00 2001 From: Zenithal Date: Thu, 7 Oct 2021 01:50:16 +0800 Subject: [PATCH] apt-sync: move_file_in handling src/file being dir Related to "2543b0f apt-sync: fix deep pkgidx_file download error: no parent dir" In this commit, src/file can be some directory like .tmp/by-hash, when dst/by-hash is not empty dir, rename would fail. Not using replace() is suggested by @happyaron since this may behave oddly when the disk is full as this function is not atomic. --- apt-sync.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apt-sync.py b/apt-sync.py index 24f165d..df08e5b 100755 --- a/apt-sync.py +++ b/apt-sync.py @@ -105,7 +105,11 @@ def move_files_in(src: Path, dst: Path): empty = False print(f"moving {file} to {dst}") # shutil.move(str(file), str(dst)) - file.rename(dst / file.name) # Overwrite files + if file.is_dir(): + (dst / file.name).mkdir(parents=True, exist_ok=True) + move_files_in(file, dst / file.name) + else: + file.rename(dst / file.name) # Overwrite files if empty: print(f"{src} is empty")