* Get all file recursively * @param {Tree} parent - An array to store files * @param {Tree} [root] - Root path
(parent, root, options = {})
| 262 | * @param {Tree} [root] - Root path |
| 263 | */ |
| 264 | async function getAllFiles(parent, root, options = {}) { |
| 265 | root = root || parent.root; |
| 266 | if (!parent.children || !root.isConnected) return; |
| 267 | |
| 268 | if (supportsNativeWorkspace(root.url)) { |
| 269 | return getAllFilesNative(parent, root, options); |
| 270 | } |
| 271 | |
| 272 | try { |
| 273 | const entries = await fsOperation(parent.url).lsDir(); |
| 274 | const promises = []; |
| 275 | |
| 276 | for (const item of entries) { |
| 277 | promises.push(createChildTree(parent, item, root)); |
| 278 | } |
| 279 | |
| 280 | await Promise.all(promises); |
| 281 | } catch (error) { |
| 282 | // retry after 3s |
| 283 | parent.retriedCount += 1; |
| 284 | if (parent.retriedCount > settings.value.maxRetryCount) return; |
| 285 | if (settings.value.showRetryToast) { |
| 286 | toast(`retrying: ${parent.path}`); |
| 287 | } |
| 288 | |
| 289 | setTimeout(() => { |
| 290 | // why not outside? because parent may be removed |
| 291 | if (!root.isConnected) return; |
| 292 | parent.children.length = 0; |
| 293 | getAllFiles(parent, root, options); |
| 294 | }, 3000); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | function supportsNativeWorkspace(url = "") { |
| 299 | return ( |
no test coverage detected