Use shutil.move to move data instead of Path.rename

Path.rename() cannot move data to different drives. It can only rename the path reference on the same file system. However, shutil.move() will move the data while also changing it's name.
This commit is contained in:
varyg
2023-02-12 20:25:39 +01:00
committed by rlaphoenix
parent b25e6c5ce5
commit bb9e85d777
3 changed files with 8 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import asyncio
import logging
import re
import shutil
import subprocess
from enum import Enum
from pathlib import Path
@@ -312,7 +313,8 @@ class Track:
if not self.path:
return False
target = Path(target)
ok = self.path.rename(target).resolve() == target.resolve()
ok = Path(shutil.move(self.path, target)).resolve() == target.resolve()
if ok:
self.path = target
return ok
@@ -326,7 +328,7 @@ class Track:
if not target.exists() or not self.path:
return False
self.path.unlink()
ok = target.rename(self.path) == self.path
ok = Path(shutil.move(target, self.path)).resolve() == self.path.resolve()
if not ok:
return False
return self.move(target)