fix(fs): Fix directory handling in copy and copySync functions

This commit is contained in:
2025-01-29 18:20:14 +01:00
parent f6fb28d32f
commit 40018532a7
3 changed files with 13 additions and 1 deletions

View File

@@ -75,6 +75,9 @@ export const isFile = (pathArg): boolean => {
* copies a file or directory from A to B on the local disk
*/
export const copy = async (fromArg: string, toArg: string): Promise<void> => {
if (isDirectory(fromArg) && isDirectory(toArg)) {
await remove(toArg);
}
return await plugins.fsExtra.copy(fromArg, toArg, {overwrite: true});
};
@@ -82,6 +85,9 @@ export const copy = async (fromArg: string, toArg: string): Promise<void> => {
* copies a file or directory SYNCHRONOUSLY from A to B on the local disk
*/
export const copySync = (fromArg: string, toArg: string): void => {
if (isDirectory(fromArg) && isDirectory(toArg)) {
removeSync(toArg);
}
return plugins.fsExtra.copySync(fromArg, toArg, {overwrite: true});
};