upload: early check of system permissions
Massimo Melina committed
Aug 10, 2025 at 19:22 UTC
51ab2141bd880b738fe30666e33eda9dc18f0683
1 file changed
+11
src/upload.ts
+11
@@ -109,6 +109,17 @@ export function uploadWriter(base: VfsNode, baseUri: string, path: string, ctx:
109
setUploadMeta(dir, ctx)
110
// use temporary name while uploading
111
const tempName = getUploadTempFor(fullPath)
112
+ // try to catch errors early (sync): this is avoiding on chrome139 when uploading a big file (1GB) to get miss the error code and have to make a `simulate`
113
+ try { fs.accessSync(tempName, fs.constants.W_OK) }
114
+ catch {
115
+ try {
116
+ fs.closeSync(fs.openSync(tempName, 'w'))
117
+ fs.unlinkSync(tempName)
118
+ }
119
+ catch(e: any) {
120
+ return fail(HTTP_SERVER_ERROR, e.code)
121
+ }
122
+ }
123
const stats = try_(() => fs.statSync(tempName))
124
const resumableSize = stats?.size || 0
125
// checks for resume feature