fix: error "undefined reading source" while uploading
Massimo Melina committed
Sep 20, 2024 at 17:54 UTC
97f4576005d7146ba10d102e359efce3bca92776
1 file changed
+3
-2
src/upload.ts
+3
-2
@@ -63,8 +63,9 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
63
else
64
try {
65
// refer to the source of the closest node that actually belongs to the vfs, so that cache is more effective
66
- let closestVfsNode: typeof base | undefined = base
67
- while (closestVfsNode && !closestVfsNode.original) closestVfsNode = closestVfsNode.parent
66
+ let closestVfsNode = base // if base=root, there's no parent and no original
67
+ while (closestVfsNode?.parent && !closestVfsNode.original)
68
+ closestVfsNode = closestVfsNode.parent! // if it's not original, it surely has a parent
69
const statDir = closestVfsNode!.source!
70
if (!Object.hasOwn(diskSpaceCache, statDir)) {
71
const c = diskSpaceCache[statDir] = getDiskSpaceSync(statDir)