mkdir: return 403 error for mkdir action in the root dir

This commit is contained in:
XiaochenCui
2025-07-15 10:56:25 -07:00
committed by Eric Dubé
parent c75d9b9544
commit 0a8e4f985e
@@ -275,11 +275,20 @@ class HLMkdir extends HLFilesystemOperation {
console.log('USING PARENT', parent_node.selector.describe());
let target_basename = _path.basename(values.path);
// "top_parent" is the immediate parent of the target directory
// (e.g: /home/foo/bar -> /home/foo)
const top_parent = values.create_missing_parents
? await this._create_top_parent({ top_parent: parent_node })
: await this._get_existing_top_parent({ top_parent: parent_node })
;
if ( top_parent.isRoot ) {
// root directory is read-only
throw APIError.create('forbidden', null, {
message: 'Cannot create directories in the root directory.'
});
}
// `parent_node` becomes the parent of the last directory name
// specified under `path`.
parent_node = await this._create_parents({