Skip to content

Commit

Permalink
Rework conditions in mv
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanduplenskikh committed Nov 14, 2024
1 parent d931ff0 commit 249ccf3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions node/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 249ccf3

Please sign in to comment.