fix: admin/fs: prevent rename with existing name

Massimo Melina committed Feb 22, 2023 at 07:28 UTC 460eaa154ddbbf2e2a22fe98f0869921e0ac58bf
1 file changed +3
src/api.vfs.ts
+3
@@ -81,6 +81,9 @@ const apis: ApiHandlers = {
81 if (!n)
82 return new ApiError(HTTP_NOT_FOUND, 'path not found')
83 props = pickProps(props, ['name','source','masks','default', ...Object.keys(defaultPerms)])
84 + const parent = await urlToNodeOriginal(dirname(uri))
85 + if (parent?.children?.find(x => getNodeName(x) === props.name))
86 + return new ApiError(HTTP_CONFLICT, 'name already present')
87 props = objSameKeys(props, v => v === null ? undefined : v) // null is a way to serialize undefined, that will restore default values
88 if (props.masks && typeof props.masks !== 'object')
89 delete props.masks