From f70df59e21f9fa7bd545ec562afd24516755745f Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:21:04 +0200 Subject: [PATCH] [bugfix] dont move the folder if all subitem in the folder already exist in the destination --- src/main/helpers/fs.helpers.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/helpers/fs.helpers.ts b/src/main/helpers/fs.helpers.ts index fe21bc52..480effec 100644 --- a/src/main/helpers/fs.helpers.ts +++ b/src/main/helpers/fs.helpers.ts @@ -84,7 +84,7 @@ export function moveFolderContent(src: string, dest: string, option?: MoveOption return new Observable(subscriber => { subscriber.next(progress); (async () => { - const srcExist = await pathExist(src); + const srcExist = await pathExists(src); if (!srcExist) { return subscriber.complete(); @@ -98,7 +98,14 @@ export function moveFolderContent(src: string, dest: string, option?: MoveOption for(const file of files){ const srcFullPath = path.join(src, file); const destFullPath = path.join(dest, file); - await move(srcFullPath, destFullPath, option); + + const srcChilds = await readdir(srcFullPath, { encoding: "utf-8", recursive: true }); + const allChildsAlreadyExist = srcChilds.every(child => pathExistsSync(path.join(destFullPath, child))); + + if(!allChildsAlreadyExist){ + await move(srcFullPath, destFullPath, option); + } + progress.current++; subscriber.next(progress); }