From f622bd8a4b82a1ef4d70cfa84a8cfe89a91ffc9e Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Fri, 8 Mar 2024 15:33:05 -0800 Subject: [PATCH] Add a copystat call in beet's util move, to copy permissions. --- beets/util/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 00558e90a..0061d3ba0 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -503,10 +503,7 @@ def copy(path: bytes, dest: bytes, replace: bool = False): def move(path: bytes, dest: bytes, replace: bool = False): """Rename a file. `dest` may not be a directory. If `dest` already exists, raises an OSError unless `replace` is True. Has no effect if - `path` is the same as `dest`. If the paths are on different - filesystems (or the rename otherwise fails), a copy is attempted - instead, in which case metadata will *not* be preserved. Paths are - translated to system paths. + `path` is the same as `dest`. Paths are translated to system paths. """ if os.path.isdir(syspath(path)): raise FilesystemError("source is directory", "move", (path, dest)) @@ -536,6 +533,9 @@ def move(path: bytes, dest: bytes, replace: bool = False): finally: tmp.close() + # Copy file metadata + shutil.copystat(syspath(path), tmp.name) + # Move the copied file into place. try: os.replace(tmp.name, syspath(dest))