diff --git a/changelog.md b/changelog.md index 1a21db3..6f03b5d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-01-29 - 11.1.9 - fix(fs) +Fix directory handling in copy and copySync functions + +- Ensured existing directories at destination are removed before copying over them in async copy. +- Added a similar check and handling for synchronous copySync when destination is a directory. + ## 2025-01-29 - 11.1.8 - fix(fs) Fixed copy and copySync functions to ensure they always overwrite files. diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 2d223d5..222462a 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartfile', - version: '11.1.8', + version: '11.1.9', description: 'Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.' } diff --git a/ts/fs.ts b/ts/fs.ts index a502c0c..e92c000 100644 --- a/ts/fs.ts +++ b/ts/fs.ts @@ -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 => { + 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 => { * 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}); };