fix: recursive delete error

This commit is contained in:
KernelDeimos
2025-02-17 15:31:37 -05:00
parent d0f32ee2b8
commit 7e76b657bb
2 changed files with 15 additions and 6 deletions

View File

@@ -31,6 +31,9 @@ class LLRmDir extends LLFilesystemOperation {
actor,
descendants_only,
recursive,
// internal use only - not for clients
ignore_not_empty,
max_tasks = 8,
} = this.values;
@@ -61,7 +64,7 @@ class LLRmDir extends LLFilesystemOperation {
await target.get('uid')
);
if ( children.length > 0 && ! recursive ) {
if ( children.length > 0 && ! recursive && ! ignore_not_empty ) {
throw APIError.create('not_empty');
}
@@ -100,7 +103,13 @@ class LLRmDir extends LLFilesystemOperation {
await tasks.awaitAll();
if ( ! descendants_only ) {
await target.provider.rmdir({ context, node: target });
await target.provider.rmdir({
context,
node: target,
options: {
ignore_not_empty: true,
},
});
}
}
}

View File

@@ -367,7 +367,7 @@ class PuterFSProvider extends putility.AdvancedBase {
await this.rmnode_({ context, node });
}
async rmdir ({ context, node }) {
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.');
@@ -386,15 +386,15 @@ class PuterFSProvider extends putility.AdvancedBase {
await node.get('uid')
);
if ( children.length > 0 ) {
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 });
await this.rmnode_({ context, node, options });
}
async rmnode_ ({ context, node }) {
async rmnode_ ({ context, node, options }) {
// Services
const services = context.get('services');
const svc_size = services.get('sizeService');