mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 08:30:39 +00:00
fs/mkdir: update check logic, update test cases
This commit is contained in:
@@ -280,23 +280,8 @@ class HLMkdir extends HLFilesystemOperation {
|
||||
}
|
||||
|
||||
let parent_node = values.parent || await fs.node(new RootNodeSelector());
|
||||
if ( parent_node.isRoot ) {
|
||||
// root directory is read-only
|
||||
throw APIError.create('forbidden', null, {
|
||||
message: 'Cannot create directories in the root directory.'
|
||||
});
|
||||
}
|
||||
console.log('USING PARENT', parent_node.selector.describe());
|
||||
|
||||
// TODO: this can be removed upon completion of: https://github.com/HeyPuter/puter/issues/1352
|
||||
if ( parent_node.isRoot ) {
|
||||
// root directory is read-only
|
||||
throw APIError.create('forbidden', null, {
|
||||
message: 'Cannot create directories in the root directory.'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let target_basename = _path.basename(values.path);
|
||||
|
||||
// "top_parent" is the immediate parent of the target directory
|
||||
@@ -306,6 +291,14 @@ class HLMkdir extends HLFilesystemOperation {
|
||||
: await this._get_existing_top_parent({ top_parent: parent_node })
|
||||
;
|
||||
|
||||
// TODO: this can be removed upon completion of: https://github.com/HeyPuter/puter/issues/1352
|
||||
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({
|
||||
|
||||
@@ -193,7 +193,7 @@ module.exports = class TestSDK {
|
||||
this.mkdir_v2 = async (parent, path, opts) => {
|
||||
const res = await this.post('mkdir', {
|
||||
parent: p(parent),
|
||||
path: p(path),
|
||||
path: path, // "path" arg should remain relative in this api
|
||||
...(opts ?? {})
|
||||
});
|
||||
return res.data;
|
||||
|
||||
@@ -152,19 +152,38 @@ module.exports = {
|
||||
create_missing_parents: true,
|
||||
});
|
||||
expect(result.name).equal('c');
|
||||
|
||||
await t.case('can stat directories along the path', async () => {
|
||||
let stat = await t.stat('a');
|
||||
expect(stat.name).equal('a');
|
||||
|
||||
stat = await t.stat('a/b');
|
||||
expect(stat.name).equal('b');
|
||||
|
||||
stat = await t.stat('a/b/c');
|
||||
expect(stat.name).equal('c');
|
||||
});
|
||||
});
|
||||
|
||||
await t.case('can stat the directory', async () => {
|
||||
const stat = await t.stat(path);
|
||||
expect(stat.name).equal('c');
|
||||
});
|
||||
await t.case('composite path', async () => {
|
||||
const result = await t.mkdir_v2('1/2', '3/4', {
|
||||
create_missing_parents: true,
|
||||
});
|
||||
expect(result.name).equal('4');
|
||||
|
||||
await t.case('can stat the parent directory', async () => {
|
||||
let stat = await t.stat('a');
|
||||
expect(stat.name).equal('a');
|
||||
await t.case('can stat directories along the path', async () => {
|
||||
let stat = await t.stat('1');
|
||||
expect(stat.name).equal('1');
|
||||
|
||||
stat = await t.stat('a/b');
|
||||
expect(stat.name).equal('b');
|
||||
stat = await t.stat('1/2');
|
||||
expect(stat.name).equal('2');
|
||||
|
||||
stat = await t.stat('1/2/3');
|
||||
expect(stat.name).equal('3');
|
||||
|
||||
stat = await t.stat('1/2/3/4');
|
||||
expect(stat.name).equal('4');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user