@samitouri / QOSami-HFS / commits / 3cf6ab80

upload: less writing if upload-meta is written after rename

Massimo Melina committed Dec 16, 2023 at 18:34 UTC 3cf6ab8008b83d7d678c8c6cfb55c0d18589829f
1 file changed +1 -1
src/upload.ts
+1 -1
@@ -95,7 +95,6 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
95 ret.once('close', async () => {
96 if (!ctx.req.aborted) {
97 let dest = fullPath
98 - await setUploadMeta(tempName, ctx)
98 if (dontOverwriteUploading.get() && fs.existsSync(dest) && !overwriteAnyway()) {
99 const ext = extname(dest)
100 const base = dest.slice(0, -ext.length)
@@ -104,6 +103,7 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
103 while (fs.existsSync(dest))
104 }
105 return fs.rename(tempName, dest, err => {
106 + setUploadMeta(err ? tempName : dest, ctx)
107 if (err)
108 console.error("couldn't rename temp to", dest, String(err))
109 else if (ctx.query.comment)