@samitouri / QOSami-HFS / commits / 35521725

fix: upload is stuck when missing system permission on a folder

Massimo Melina committed Aug 8, 2025 at 11:00 UTC 35521725ffd0b3a3bfe710b68e259faa4a0a7def
1 file changed +9 -1
src/upload.ts
+9 -1
@@ -2,7 +2,7 @@ import { getNodeByName, statusCodeForMissingPerm, VfsNode } from './vfs'
2 import Koa from 'koa'
3 import {
4 HTTP_CONFLICT, HTTP_FOOL, HTTP_INSUFFICIENT_STORAGE, HTTP_RANGE_NOT_SATISFIABLE, HTTP_BAD_REQUEST, HTTP_NO_CONTENT,
5 - HTTP_PRECONDITION_FAILED, MTIME_CHECK,
5 + HTTP_PRECONDITION_FAILED, MTIME_CHECK, HTTP_SERVER_ERROR,
6 } from './const'
7 import { basename, dirname, extname, join } from 'path'
8 import fs from 'fs'
@@ -152,10 +152,18 @@ export function uploadWriter(base: VfsNode, baseUri: string, path: string, ctx:
152 writeStream.on('data', () => setTimeout(() => tracked.got = bytesGot()))
153
154 const lockMiddleware = pendingPromise<string>() // expose outside, to let know when all operations stopped
155 + let errored: any
156 + fileStream.on('error', (e: any) => {
157 + console.warn('file error while uploading', path, ':', e.message)
158 + errored = e
159 + fail(HTTP_SERVER_ERROR, e.code) // don't send e.message as it may contain a disk paths we don't want to leak
160 + })
161 writeStream.once('close', async () => {
162 try {
163 ctx.state.uploadSize = bytesGot() // in case content-length is not specified
164 await new Promise(res => fileStream.close(res)) // this only seems necessary on Windows
165 + if (errored)
166 + return
167 if (simulate)
168 return rm(tempName).catch(() => {})
169 if (ctx.isAborted()) { // in the very unlikely case the connection is interrupted between last-byte and here, we still consider it unfinished, as the client had no way to know, and will resume, but it would get an error if we finish the process