Skip to content

Commit

Permalink
Fixes bug in FileSystem copy method
Browse files Browse the repository at this point in the history
Updates file copying logic to use relative paths to formulate final copy source and destination paths.
  • Loading branch information
refringe committed Jan 10, 2025
1 parent 49286ec commit 0b287a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions project/src/utils/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ export class FileSystem {
const tasks: Promise<void>[] = [];

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.
}
}

Expand Down
9 changes: 5 additions & 4 deletions project/src/utils/FileSystemSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
}
Expand Down

0 comments on commit 0b287a8

Please sign in to comment.