Add a copystat call in beet's util move, to copy permissions.

This commit is contained in:
Aidan Epstein 2024-03-08 15:33:05 -08:00
parent b09806e0df
commit f622bd8a4b

View file

@ -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))