@samitouri / QOSami-HFS / commits / 55ff5baf

fix: error deleting a file

Massimo Melina committed Mar 2, 2025 at 19:44 UTC 55ff5bafbb13607fc2ef3523d761c0bf1b27a616
2 files changed +6 -4
src/fileAttr.ts
+5 -3
@@ -21,14 +21,16 @@ const FILE_ATTR_PREFIX = 'user.hfs.' // user. prefix to be linux compatible
21
22 /* @param v must be JSON-able or undefined */
23 export async function storeFileAttr(path: string, k: string, v: any) {
24 - const s = await stat(path) // since we don't have fsx.remove, we simulate it with an empty string
24 + const s = await stat(path).catch(() => null)
25 + // since we don't have fsx.remove, we simulate it with an empty string
26 if (await fsx?.set(path, FILE_ATTR_PREFIX + k, v === undefined ? '' : JSON.stringify(v)).then(() => 1, () => 0)) {
26 - if (IS_WINDOWS) utimes(path, s.atime, s.mtime) // restore timestamps, necessary only on Windows
27 + if (s && IS_WINDOWS) utimes(path, s.atime, s.mtime) // restore timestamps, necessary only on Windows
28 return true
29 }
30 // fallback to our kv-storage
31 if (!fileAttrDb.isOpen())
31 - await fileAttrDb.open(FN)
32 + if (!s && !v) return // file was probably deleted, and we were asked to remove a possible attribute, but there's no fileAttrDb, so we are done, don't create the db file for nothing
33 + else await fileAttrDb.open(FN)
34 // pipe should be a safe separator
35 return await fileAttrDb.put(`${path}|${k}`, v)?.catch((e: any) => {
36 console.error("couldn't store metadata on", path, String(e.message || e))
src/misc.ts
+1 -1
@@ -153,7 +153,7 @@ export async function deleteNode(ctx: Koa.Context, node: VfsNode, uri: string) {
153 return null // stop
154 ctx.logExtra(null, { target: decodeURI(uri) })
155 await rm(source, { recursive: true })
156 - void setCommentFor(source, '')
156 + void setCommentFor(source, '') // necessary only to clean a possible descript.ion or kvstorage
157 return true
158 } catch (e: any) {
159 return e