Skip to content

Commit 807c3ba

Browse files
committed
fix: mkdir with create_missing when some parents exist
There was an issue affecting mkdir requests with create_missing_parents set to true which prevented the correct behavior if some of the listed parents were already present. This commit ensures mkdir selects the deepest existing node as the parent before proceeding.
1 parent fb70251 commit 807c3ba

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/backend/src/filesystem/hl_operations/hl_mkdir.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,35 @@ class HLMkdir extends HLFilesystemOperation {
386386
}
387387

388388
async _create_parents ({ parent_node }) {
389-
const { values } = this;
389+
const { context, values } = this;
390390
const { _path } = this.modules;
391391

392+
const fs = context.get('services').get('filesystem');
393+
394+
// Determine the deepest existing node
395+
let deepest_existing = parent_node;
396+
let remaining_path = _path.dirname(values.path).split('/').filter(Boolean);
397+
{
398+
const parts = remaining_path.slice();
399+
for (;;) {
400+
if ( remaining_path.length === 0 ) {
401+
return deepest_existing;
402+
}
403+
const component = remaining_path[0];
404+
const next_selector = new NodeChildSelector(deepest_existing.selector, component);
405+
const next_node = await fs.node(next_selector);
406+
if ( ! await next_node.exists() ) {
407+
break;
408+
}
409+
deepest_existing = next_node;
410+
remaining_path.shift();
411+
}
412+
}
413+
392414
const tree_op = new MkTree();
393415
await tree_op.run({
394-
parent: parent_node,
395-
tree: [_path.dirname(values.path)],
416+
parent: deepest_existing,
417+
tree: [remaining_path.join('/')],
396418
});
397419

398420
this.parent_directories_created = tree_op.directories_created;

0 commit comments

Comments
 (0)