fix: admin/fs: prevent creation of a folder with an existing name https://github.com/rejetto/hfs/issues/112

Massimo Melina committed Feb 22, 2023 at 07:21 UTC a3c1d3efd15bdb7f6cf6b088079a00c6357bdb6f
1 file changed +3 -3
src/api.vfs.ts
+3 -3
@@ -99,10 +99,10 @@ const apis: ApiHandlers = {
99 return new ApiError(HTTP_NOT_ACCEPTABLE, 'invalid parent')
100 if (isWindowsDrive(source))
101 source += '\\' // slash must be included, otherwise it will refer to the cwd of that drive
102 - const a = n.children || (n.children = [])
103 - if (source && a.find(x => x.source === source))
102 + n.children ||= []
103 + if (n.children.find(x => x.source === source || getNodeName(x) === name))
104 return new ApiError(HTTP_CONFLICT, 'already present')
105 - a.unshift({ source, name })
105 + n.children.unshift({ source, name })
106 await saveVfs()
107 return {}
108 },