mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-05 20:50:22 -06:00
dev(puterfs): move rmdir to extension
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }) {
|
||||
|
||||
Reference in New Issue
Block a user