dev(puterfs): move rmdir to extension

This commit is contained in:
KernelDeimos
2025-11-05 14:57:31 -05:00
committed by Eric Dubé
parent 3b3b9d0ee0
commit e8d9b7b35d
2 changed files with 21 additions and 22 deletions

View File

@@ -52,9 +52,27 @@ class PuterFSProvider {
await this.#rmnode({ context, node, options });
}
async rmdir ({ context, node, options = {} }) {
if ( await node.get('type') !== TYPE_DIRECTORY ) {
throw new APIError(409, 'Cannot rmdir a file.');
}
if ( await node.get('immutable') ) {
throw APIError.create('immutable');
}
const children = await svc_fsEntry.fast_get_direct_descendants(await node.get('uid'));
if ( children.length > 0 && !options.ignore_not_empty ) {
throw APIError.create('not_empty');
}
await this.#rmnode({ context, node, options });
}
async #rmnode ({ node, options }) {
// Services
if ( ! options.override_immutable && await node.get('immutable') ) {
if ( !options.override_immutable && await node.get('immutable') ) {
throw new APIError(403, 'File is immutable.');
}

View File

@@ -415,27 +415,8 @@ class PuterFSProvider extends putility.AdvancedBase {
}
async rmdir({ context, node, options = {} }) {
if ( await node.get('type') !== TYPE_DIRECTORY ) {
console.log(`\x1B[31;1m===D1====${await node.get('path')}=========\x1B[0m`);
throw new APIError(409, 'Cannot rmdir a file.');
}
if ( await node.get('immutable') ) {
console.log(`\x1B[31;1m===D2====${await node.get('path')}=========\x1B[0m`);
throw APIError.create('immutable');
}
// Services
const svc_fsEntry = this.#services.get('fsEntryService');
const children = await svc_fsEntry.fast_get_direct_descendants(await node.get('uid'));
if ( children.length > 0 && ! options.ignore_not_empty ) {
console.log(`\x1B[31;1m===D3====${await node.get('path')}=========\x1B[0m`);
throw APIError.create('not_empty');
}
await this.#rmnode({ context, node, options });
console.error('This .rmdir should not be called!');
process.exit(1);
}
async #rmnode({ node, options }) {