Use the exclusive move for save rename and widen its copy fallback

Fall back to copying on any link error except EEXIST, since filesystems
without hard links report it with several codes (EISDIR on exFAT under
Windows, ENOSYS on some FUSE mounts). Rename now goes through the same
move so it also gets the fallback and the rollback. Only report a
missing source save on transfer when the source is actually missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 authored and Cooldude2606 committed 2026-10-24 00:22:17 +01:00
1 parent e16d0bc410
commit 5355a0170a
1 file changed
+8 -8
+8 -8
View File
@@ -42,8 +42,9 @@ async function moveSaveExclusive(sourcePath: string, targetPath: string) {
try { try {
await fs.link(sourcePath, targetPath); await fs.link(sourcePath, targetPath);
} catch (err: any) { } catch (err: any) {
// Hard links are not possible across filesystems and on some filesystems. // Hard links fail across filesystems and on some filesystems with
if (!["EXDEV", "EPERM", "ENOTSUP"].includes(err.code)) { // varying codes, the copy is still exclusive.
if (err.code === "EEXIST") {
throw err; throw err;
} }
await copySaveExclusive(sourcePath, targetPath); await copySaveExclusive(sourcePath, targetPath);
@@ -1054,13 +1055,10 @@ export default class Host extends lib.Link {
checkRequestSaveName(newName); checkRequestSaveName(newName);
let instance = this.getRequestInstance(instanceId); let instance = this.getRequestInstance(instanceId);
try { try {
// Link save in the new location. await moveSaveExclusive(
await fs.link(
path.join(instance.path, "saves", oldName), path.join(instance.path, "saves", oldName),
path.join(instance.path, "saves", newName), path.join(instance.path, "saves", newName),
); );
// Unlink save in old location.
await fs.unlink(path.join(instance.path, "saves", oldName));
} catch (err: any) { } catch (err: any) {
if (err.code === "EEXIST") { if (err.code === "EEXIST") {
throw new lib.RequestError(`${newName} already exists`); throw new lib.RequestError(`${newName} already exists`);
@@ -1125,14 +1123,16 @@ export default class Host extends lib.Link {
// For consistency with remote transfer initiated through pullSave the // For consistency with remote transfer initiated through pullSave the
// target is renamed if it already exists. // target is renamed if it already exists.
const sourcePath = path.join(sourceInstance.path, "saves", sourceName);
try { try {
targetName = await this._moveOrCopySave( targetName = await this._moveOrCopySave(
path.join(sourceInstance.path, "saves", sourceName), sourcePath,
path.join(targetInstance.path, "saves", targetName), path.join(targetInstance.path, "saves", targetName),
copy, copy,
); );
} catch (err: any) { } catch (err: any) {
if (err.code === "ENOENT") { // ENOENT may also come from a missing target saves folder.
if (err.code === "ENOENT" && !await fs.access(sourcePath).then(() => true, () => false)) {
throw new lib.RequestError(`${sourceName} does not exist`); throw new lib.RequestError(`${sourceName} does not exist`);
} }
throw err; throw err;