From e8d9b7b35d3bd74627951556f9644af5bc742cf9 Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Wed, 5 Nov 2025 14:57:31 -0500 Subject: [PATCH] dev(puterfs): move rmdir to extension --- extensions/puterfs/main.js | 20 +++++++++++++++- .../modules/puterfs/lib/PuterFSProvider.js | 23 ++----------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/extensions/puterfs/main.js b/extensions/puterfs/main.js index f210bd79..4bd982e6 100644 --- a/extensions/puterfs/main.js +++ b/extensions/puterfs/main.js @@ -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.'); } diff --git a/src/backend/src/modules/puterfs/lib/PuterFSProvider.js b/src/backend/src/modules/puterfs/lib/PuterFSProvider.js index 25130337..42776458 100644 --- a/src/backend/src/modules/puterfs/lib/PuterFSProvider.js +++ b/src/backend/src/modules/puterfs/lib/PuterFSProvider.js @@ -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 }) {