From 249ccf37f67d941c1c361879f7cd93b58ed9ed8b Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:23:07 +0100 Subject: [PATCH] Rework conditions in mv --- node/task.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/node/task.ts b/node/task.ts index d05df5f78..2e2927433 100644 --- a/node/task.ts +++ b/node/task.ts @@ -1021,14 +1021,15 @@ export function cp(source: string, dest: string, options?: string, continueOnErr */ export function mv(source: string, dest: string, options?: string, continueOnError?: boolean): void { try { - const isNoClobber = options?.toLowerCase()?.includes('-n'); + const isForce = !options?.toLowerCase()?.includes('-n') && options?.toLowerCase()?.includes('-f'); + const destExists = fs.existsSync(dest); - if ((!fs.existsSync(dest))) { - throw new Error(loc('LIB_DestinationNotExist', dest)); + if (!fs.existsSync(source)) { + throw new Error(loc('LIB_PathNotFound', source)); } - if (fs.existsSync(dest) && isNoClobber) { - throw new Error(`dest file already exists: ${dest}`); + if (destExists && isForce) { + throw new Error(loc('LIB_PathNotFound', dest)); } fs.renameSync(source, dest);