fix(backup): do not create redundant subdirectory on single file backup

This commit is contained in:
dw-0
2025-10-27 09:47:09 +01:00
parent 48c0ae7227
commit 229f317025

View File

@@ -62,16 +62,16 @@ class BackupService:
target_name
or f"{source_path.stem}_{self.timestamp}{source_path.suffix}"
)
if target_path is not None:
backup_path = self._backup_root.joinpath(target_path, filename)
else:
backup_path = self._backup_root.joinpath(filename)
backup_path.mkdir(parents=True, exist_ok=True)
shutil.copy2(source_path, backup_path)
backup_dir = self._backup_root
if target_path is not None:
backup_dir = self._backup_root.joinpath(target_path)
backup_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(source_path, backup_dir.joinpath(filename))
Logger.print_ok(
f"Successfully backed up '{source_path}' to '{backup_path}'"
f"Successfully backed up '{source_path}' to '{backup_dir}'"
)
return True