From 7e76b657bb2fe811d437598471e52744a6276088 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 17 Feb 2025 15:31:37 -0500 Subject: [PATCH] fix: recursive delete error --- .../src/filesystem/ll_operations/ll_rmdir.js | 13 +++++++++++-- .../src/modules/puterfs/lib/PuterFSProvider.js | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backend/src/filesystem/ll_operations/ll_rmdir.js b/src/backend/src/filesystem/ll_operations/ll_rmdir.js index e18ad0b1..08add7c7 100644 --- a/src/backend/src/filesystem/ll_operations/ll_rmdir.js +++ b/src/backend/src/filesystem/ll_operations/ll_rmdir.js @@ -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, + }, + }); } } } diff --git a/src/backend/src/modules/puterfs/lib/PuterFSProvider.js b/src/backend/src/modules/puterfs/lib/PuterFSProvider.js index 58bf4355..0f7ce051 100644 --- a/src/backend/src/modules/puterfs/lib/PuterFSProvider.js +++ b/src/backend/src/modules/puterfs/lib/PuterFSProvider.js @@ -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');