optimization urlToNode: fail earlier

Massimo Melina committed Apr 19, 2023 at 16:40 UTC 1be4f4b9244b63632d5230e9a28e04df443aae05
1 file changed +2 -3
src/vfs.ts
+2 -3
@@ -90,6 +90,7 @@ export async function urlToNode(url: string, ctx?: Koa.Context, parent: VfsNode=
90 }
91 // does the tree node have a child that goes by this name?
92 const child = parent.children?.find(isSameFilenameAs(name))
93 + if (!child && !parent.source) return // on tree or on disk
94
95 const ret: VfsNode = {
96 ...child,
@@ -101,8 +102,6 @@ export async function urlToNode(url: string, ctx?: Koa.Context, parent: VfsNode=
102 inheritFromParent(parent, ret)
103 if (child) // yes
104 return urlToNode(rest, ctx, ret, getRest)
104 - // not in the tree, we can see consider continuing on the disk
105 - if (!parent.source) return // but then we need the current node to be linked to the disk, otherwise, we give up
105 let onDisk = name
106 if (parent.rename) { // reverse the mapping
107 for (const [from, to] of Object.entries(parent.rename))
@@ -112,7 +111,7 @@ export async function urlToNode(url: string, ctx?: Koa.Context, parent: VfsNode=
111 }
112 ret.rename = renameUnderPath(parent.rename, name)
113 }
115 - ret.source = enforceFinal('/', parent.source) + onDisk
114 + ret.source = enforceFinal('/', parent.source!) + onDisk
115 if (parent.default)
116 inheritFromParent({ mime: { '*': MIME_AUTO } }, ret)
117 if (rest)