copyFiles in parallel

This commit is contained in:
Alex Gleason committed 2025-09-12 13:41:28 -05:00
1 parent d33fa36591
commit 8e727b0b63
1 file changed
+23 -21
+23 -21
View File
@@ -27,30 +27,32 @@ export async function copyFiles(
// Directory might already exist, that's fine
}
// Copy each item
for (const item of items) {
const sourceItemPath = `${sourcePath}/${item.name}`;
const targetItemPath = `${targetPath}/${item.name}`;
// Copy each item in parallel
await Promise.all(
items.map(async (item) => {
const sourceItemPath = `${sourcePath}/${item.name}`;
const targetItemPath = `${targetPath}/${item.name}`;
try {
if (item.isDirectory()) {
console.log(`Creating directory: ${targetItemPath}`);
try {
await targetFS.mkdir(targetItemPath, { recursive: true });
} catch {
// Directory might already exist
try {
if (item.isDirectory()) {
console.log(`Creating directory: ${targetItemPath}`);
try {
await targetFS.mkdir(targetItemPath, { recursive: true });
} catch {
// Directory might already exist
}
// Recursively copy directory contents
await copyFiles(sourceFS, targetFS, sourceItemPath, targetItemPath);
} else {
console.log(`Copying file: ${sourceItemPath} -> ${targetItemPath}`);
const content = await sourceFS.readFile(sourceItemPath);
await targetFS.writeFile(targetItemPath, content);
}
// Recursively copy directory contents
await copyFiles(sourceFS, targetFS, sourceItemPath, targetItemPath);
} else {
console.log(`Copying file: ${sourceItemPath} -> ${targetItemPath}`);
const content = await sourceFS.readFile(sourceItemPath);
await targetFS.writeFile(targetItemPath, content);
} catch (itemError) {
console.warn(`Failed to copy item ${item.name}:`, itemError);
}
} catch (itemError) {
console.warn(`Failed to copy item ${item.name}:`, itemError);
}
}
})
);
console.log(`Successfully copied ${sourcePath} to ${targetPath}`);
} catch (error) {