Skip to content

Commit 249ccf3

Browse files
Rework conditions in mv
1 parent d931ff0 commit 249ccf3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

node/task.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,14 +1021,15 @@ export function cp(source: string, dest: string, options?: string, continueOnErr
10211021
*/
10221022
export function mv(source: string, dest: string, options?: string, continueOnError?: boolean): void {
10231023
try {
1024-
const isNoClobber = options?.toLowerCase()?.includes('-n');
1024+
const isForce = !options?.toLowerCase()?.includes('-n') && options?.toLowerCase()?.includes('-f');
1025+
const destExists = fs.existsSync(dest);
10251026

1026-
if ((!fs.existsSync(dest))) {
1027-
throw new Error(loc('LIB_DestinationNotExist', dest));
1027+
if (!fs.existsSync(source)) {
1028+
throw new Error(loc('LIB_PathNotFound', source));
10281029
}
10291030

1030-
if (fs.existsSync(dest) && isNoClobber) {
1031-
throw new Error(`dest file already exists: ${dest}`);
1031+
if (destExists && isForce) {
1032+
throw new Error(loc('LIB_PathNotFound', dest));
10321033
}
10331034

10341035
fs.renameSync(source, dest);

0 commit comments

Comments
 (0)