From 0b287a831af1932ad77ae4bccc39e4eb44fcd1f1 Mon Sep 17 00:00:00 2001 From: Refringe Date: Fri, 10 Jan 2025 14:17:37 -0500 Subject: [PATCH] Fixes bug in FileSystem `copy` method Updates file copying logic to use relative paths to formulate final copy source and destination paths. --- project/src/utils/FileSystem.ts | 9 +++++---- project/src/utils/FileSystemSync.ts | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/project/src/utils/FileSystem.ts b/project/src/utils/FileSystem.ts index 5eaff270..a4535d08 100644 --- a/project/src/utils/FileSystem.ts +++ b/project/src/utils/FileSystem.ts @@ -40,13 +40,14 @@ export class FileSystem { const tasks: Promise[] = []; for (const dirent of dirents) { - const srcItem = path.join(src, dirent.name); - const destItem = path.join(dest, dirent.name); + const srcPath = path.join(dirent.parentPath, dirent.name); + const srcPathRel = path.relative(src, srcPath); + const destPath = path.join(dest, srcPathRel); if (!dirent.isDirectory()) { - tasks.push(this.copyFile(srcItem, destItem, extensionsWhitelist)); + tasks.push(this.copyFile(srcPath, destPath, extensionsWhitelist)); } else { - tasks.push(fsExtra.ensureDir(destItem)); // Ensures that an empty directories are copied. + tasks.push(fsExtra.ensureDir(destPath)); // Ensures that an empty directories are copied. } } diff --git a/project/src/utils/FileSystemSync.ts b/project/src/utils/FileSystemSync.ts index ce09e772..7193d6e1 100644 --- a/project/src/utils/FileSystemSync.ts +++ b/project/src/utils/FileSystemSync.ts @@ -40,13 +40,14 @@ export class FileSystemSync { } for (const dirent of dirents) { - const srcItem = path.join(src, dirent.name); - const destItem = path.join(dest, dirent.name); + const srcPath = path.join(dirent.parentPath, dirent.name); + const srcPathRel = path.relative(src, srcPath); + const destPath = path.join(dest, srcPathRel); if (!dirent.isDirectory()) { - this.copyFile(srcItem, destItem, extensionsWhitelist); + this.copyFile(srcPath, destPath, extensionsWhitelist); } else { - fsExtra.ensureDirSync(destItem); // Ensures that empty subdirectories are copied. + fsExtra.ensureDirSync(destPath); // Ensures that empty subdirectories are copied. } } }