fix: zipping a folder without 'read' didn't consider possible children with 'read'

Massimo Melina committed Apr 7, 2023 at 13:05 UTC 1434a77472d8df40ecdbff346d95a86cc4d083ec
1 file changed +6 -6
src/vfs.ts
+6 -6
@@ -17,7 +17,7 @@ type AccountList = string[]
17 export type Who = typeof WHO_ANYONE
18 | typeof WHO_NO_ONE
19 | typeof WHO_ANY_ACCOUNT
20 - | AccountList
20 + | AccountList // empty array shouldn't be used to keep the type boolean-able
21
22 export interface VfsPerm {
23 can_read: Who
@@ -166,11 +166,6 @@ export function statusCodeForMissingPerm(node: VfsNode, perm: keyof VfsPerm, ctx
166 // it's responsibility of the caller to verify you have list permission on parent, as callers have different needs.
167 // Too many parameters: consider object, but benchmark against degraded recursion on huge folders.
168 export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=0, prefixPath:string='', requiredPerm?: keyof VfsPerm): AsyncIterableIterator<VfsNode> {
169 - if (requiredPerm && ctx
170 - && !hasPermission(parent, requiredPerm, ctx)
171 - && !masksCouldGivePermission(parent.masks))
172 - return // no permission, no reason to continue
173 -
169 const { children, source } = parent
170 const took = prefixPath ? undefined : new Set()
171 if (children)
@@ -188,6 +183,11 @@ export async function* walkNode(parent:VfsNode, ctx?: Koa.Context, depth:number=
183 }
184 if (!source)
185 return
186 + if (requiredPerm && ctx // no permission, no reason to continue (at least for dynamic elements)
187 + && !hasPermission(parent, requiredPerm, ctx)
188 + && !masksCouldGivePermission(parent.masks, requiredPerm))
189 + return
190 +
191 try {
192 let lastDir = prefixPath.slice(0, -1) || '.'
193 const map = new Map()