fix: upload not working in a folder that's a Windows drive root

Massimo Melina committed Sep 27, 2024 at 12:07 UTC 7d1af701a13c5f37473b2237c63ad7215355d361
1 file changed +5 -3
src/upload.ts
+5 -3
@@ -4,8 +4,10 @@ import { HTTP_CONFLICT, HTTP_FOOL, HTTP_PAYLOAD_TOO_LARGE, HTTP_RANGE_NOT_SATISF
4 HTTP_BAD_REQUEST } from './const'
5 import { basename, dirname, extname, join } from 'path'
6 import fs from 'fs'
7 -import { Callback, dirTraversal, loadFileAttr, pendingPromise, storeFileAttr, try_,
8 - createStreamLimiter, } from './misc'
7 +import {
8 + Callback, dirTraversal, loadFileAttr, pendingPromise, storeFileAttr, try_,
9 + createStreamLimiter, isWindowsDrive,
10 +} from './misc'
11 import { notifyClient } from './frontEndApis'
12 import { defineConfig } from './config'
13 import { getDiskSpaceSync } from './util-os'
@@ -90,7 +92,7 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
92 let overwriteRequestedButForbidden = false
93 try {
94 // if upload creates a folder, then add meta to it too
93 - if (fs.mkdirSync(dir, { recursive: true }))
95 + if (!dir.endsWith(':\\') && fs.mkdirSync(dir, { recursive: true }))
96 setUploadMeta(dir, ctx)
97 // use temporary name while uploading
98 const keepName = basename(fullPath).slice(-200)