Skip to content

Commit b8cf6df

Browse files
committed
feat: Enhance directory traversal with error handling and improved processing of entries
1 parent e9014bc commit b8cf6df

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,7 @@
21012101
// Recursive function to traverse directory structure
21022102
async function traverseDirectory(entry, path, files) {
21032103
if (entry.isFile) {
2104-
return new Promise((resolve) => {
2104+
return new Promise((resolve, reject) => {
21052105
entry.file(file => {
21062106
// Add webkitRelativePath property
21072107
const relativePath = path + file.name;
@@ -2111,25 +2111,40 @@
21112111
});
21122112
files.push(file);
21132113
resolve();
2114+
}, err => {
2115+
console.warn('Error reading file:', err);
2116+
resolve(); // Continue even if file read fails
21142117
});
21152118
});
21162119
} else if (entry.isDirectory) {
21172120
const dirReader = entry.createReader();
21182121
return new Promise((resolve) => {
2122+
const allEntries = [];
2123+
21192124
const readEntries = () => {
21202125
dirReader.readEntries(async entries => {
21212126
if (entries.length === 0) {
2127+
// Done reading this directory, now process all entries
2128+
try {
2129+
for (const childEntry of allEntries) {
2130+
await traverseDirectory(
2131+
childEntry,
2132+
path + entry.name + '/',
2133+
files
2134+
);
2135+
}
2136+
} catch (err) {
2137+
console.warn('Error traversing directory:', err);
2138+
}
21222139
resolve();
21232140
return;
21242141
}
2125-
for (const childEntry of entries) {
2126-
await traverseDirectory(
2127-
childEntry,
2128-
path + entry.name + '/',
2129-
files
2130-
);
2131-
}
2132-
readEntries(); // Continue reading if there are more entries
2142+
// Add to collection and continue reading
2143+
allEntries.push(...entries);
2144+
readEntries();
2145+
}, err => {
2146+
console.warn('Error reading directory:', err);
2147+
resolve(); // Continue even if directory read fails
21332148
});
21342149
};
21352150
readEntries();

0 commit comments

Comments
 (0)