-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getErrorCode } from "@kosko/common-utils"; | ||
import { cp, rename, rm, stat } from "node:fs/promises"; | ||
|
||
export async function move(src: string, dest: string): Promise<void> { | ||
try { | ||
await rename(src, dest); | ||
} catch (err) { | ||
if (getErrorCode(err) !== "EXDEV") throw err; | ||
|
||
await cp(src, dest, { | ||
recursive: true, | ||
errorOnExist: true, | ||
preserveTimestamps: true | ||
}); | ||
await rm(src, { recursive: true, force: true }); | ||
} | ||
} | ||
|
||
export async function fileExists(path: string): Promise<boolean> { | ||
try { | ||
const stats = await stat(path); | ||
return stats.isFile(); | ||
} catch (err) { | ||
if (getErrorCode(err) !== "ENOENT") throw err; | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters