|
2101 | 2101 | // Recursive function to traverse directory structure |
2102 | 2102 | async function traverseDirectory(entry, path, files) { |
2103 | 2103 | if (entry.isFile) { |
2104 | | - return new Promise((resolve) => { |
| 2104 | + return new Promise((resolve, reject) => { |
2105 | 2105 | entry.file(file => { |
2106 | 2106 | // Add webkitRelativePath property |
2107 | 2107 | const relativePath = path + file.name; |
|
2111 | 2111 | }); |
2112 | 2112 | files.push(file); |
2113 | 2113 | resolve(); |
| 2114 | + }, err => { |
| 2115 | + console.warn('Error reading file:', err); |
| 2116 | + resolve(); // Continue even if file read fails |
2114 | 2117 | }); |
2115 | 2118 | }); |
2116 | 2119 | } else if (entry.isDirectory) { |
2117 | 2120 | const dirReader = entry.createReader(); |
2118 | 2121 | return new Promise((resolve) => { |
| 2122 | + const allEntries = []; |
| 2123 | + |
2119 | 2124 | const readEntries = () => { |
2120 | 2125 | dirReader.readEntries(async entries => { |
2121 | 2126 | 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 | + } |
2122 | 2139 | resolve(); |
2123 | 2140 | return; |
2124 | 2141 | } |
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 |
2133 | 2148 | }); |
2134 | 2149 | }; |
2135 | 2150 | readEntries(); |
|
0 commit comments