fix: (regression 0.41.0) incomplete search in case you had your vfs with a real folder within a folder

Massimo Melina committed May 9, 2023 at 01:01 UTC de5dab10f656cba17077ee2746c0b4a4505054b2
1 file changed +5 -4
src/vfs.ts
+5 -4
@@ -223,6 +223,7 @@ export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=
223 const { children, source } = parent
224 const took = prefixPath ? undefined : new Set()
225 const maskApplier = parentMaskApplier(parent)
226 + const parentsCache = new Map() // we use this only if depth > 0
227 if (children)
228 for (const child of children) {
229 const nodeName = getNodeName(child)
@@ -235,6 +236,7 @@ export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=
236 catch { continue }
237 yield item
238 if (!depth || !await nodeIsDirectory(child).catch(() => false)) continue
239 + parentsCache.set(name, item)
240 inheritMasks(item, parent, nodeName)
241 if (!ctx || hasPermission(item, 'can_list', ctx)) // check perm before recursion
242 yield* walkNode(item, ctx, depth - 1, name + '/')
@@ -248,8 +250,7 @@ export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=
250
251 try {
252 let lastDir = prefixPath.slice(0, -1) || '.'
251 - const map = new Map()
252 - map.set(lastDir, parent)
253 + parentsCache.set(lastDir, parent)
254 // it's important to keep using dirStream in deep-mode, as it is manyfold faster (it parallelizes)
255 for await (const [path, isFolder] of dirStream(source, depth)) {
256 if (ctx?.req.aborted)
@@ -259,7 +260,7 @@ export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=
260 if (depth) {
261 const dir = dirname(name)
262 if (dir !== lastDir)
262 - parent = map.get(lastDir = dir)
263 + parent = parentsCache.get(lastDir = dir)
264 }
265
266 const item: VfsNode = {
@@ -270,7 +271,7 @@ export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=
271 }
272 if (!canSee(item)) continue
273 if (isFolder)
273 - map.set(name, item)
274 + parentsCache.set(name, item)
275 yield item
276 }
277 }