From 2e6224825fb7042a3aa18886ef0c9d4792b11231 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:38:27 +0100 Subject: [PATCH] [bugfix] Linking a folder was not possible if the folder contained files (already in master) --- src/main/helpers/fs.helpers.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/helpers/fs.helpers.ts b/src/main/helpers/fs.helpers.ts index 0072398c..7dc13dfb 100644 --- a/src/main/helpers/fs.helpers.ts +++ b/src/main/helpers/fs.helpers.ts @@ -78,7 +78,6 @@ export async function getFilesInFolder(folderPath: string): Promise { return dirEntries.filter(entry => entry.isFile()).map(file => path.join(folderPath, file.name)); } - export function moveFolderContent(src: string, dest: string, option?: MoveOptions): Observable { const progress: Progression = { current: 0, total: 0 }; return new Observable(subscriber => { @@ -92,17 +91,17 @@ export function moveFolderContent(src: string, dest: string, option?: MoveOption await ensureFolderExist(dest); - const files = await readdir(src, { encoding: "utf-8" }); + const files = await readdir(src, { encoding: "utf-8", withFileTypes: true }); progress.total = files.length; for(const file of files){ - const srcFullPath = path.join(src, file); - const destFullPath = path.join(dest, file); + const srcFullPath = path.join(src, file.name); + const destFullPath = path.join(dest, file.name); - const srcChilds = await readdir(srcFullPath, { encoding: "utf-8", recursive: true }); + const srcChilds = file.isDirectory() ? await readdir(srcFullPath, { encoding: "utf-8", recursive: true }) : []; const allChildsAlreadyExist = srcChilds.every(child => pathExistsSync(path.join(destFullPath, child))); - if(!allChildsAlreadyExist){ + if(file.isFile() || !allChildsAlreadyExist){ await move(srcFullPath, destFullPath, option); }