mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Migrate os calls to pathlib calls in hardlink util function
See discussion here: https://github.com/beetbox/beets/pull/5684#discussion_r2502432781
This commit is contained in:
parent
0e74605efd
commit
b405d2fded
1 changed files with 6 additions and 4 deletions
|
|
@ -578,12 +578,14 @@ def hardlink(path: bytes, dest: bytes, replace: bool = False):
|
||||||
if samefile(path, dest):
|
if samefile(path, dest):
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.exists(syspath(dest)) and not replace:
|
# Dereference symlinks, expand "~", and convert relative paths to absolute
|
||||||
|
origin_path = Path(os.fsdecode(path)).expanduser().resolve()
|
||||||
|
dest_path = Path(os.fsdecode(dest)).expanduser().resolve()
|
||||||
|
|
||||||
|
if dest_path.exists() and not replace:
|
||||||
raise FilesystemError("file exists", "rename", (path, dest))
|
raise FilesystemError("file exists", "rename", (path, dest))
|
||||||
try:
|
try:
|
||||||
# This step dereferences any symlinks and converts to an absolute path
|
dest_path.hardlink_to(origin_path)
|
||||||
resolved_origin = Path(syspath(path)).resolve()
|
|
||||||
os.link(resolved_origin, syspath(dest))
|
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
raise FilesystemError(
|
raise FilesystemError(
|
||||||
"OS does not support hard links.link",
|
"OS does not support hard links.link",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue