1717 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1818 */
1919const APIError = require ( "../../api/APIError" ) ;
20+ const { MemoryFSProvider } = require ( "../../modules/puterfs/customfs/MemoryFSProvider" ) ;
2021const { ParallelTasks } = require ( "../../util/otelutil" ) ;
2122const FSNodeContext = require ( "../FSNodeContext" ) ;
2223const { NodeUIDSelector } = require ( "../node/selectors" ) ;
2324const { LLFilesystemOperation } = require ( "./definitions" ) ;
2425const { LLRmNode } = require ( './ll_rmnode' ) ;
2526
2627class LLRmDir extends LLFilesystemOperation {
27- async _run ( ) {
28+ async _run ( ) {
2829 const {
2930 target,
3031 user,
3132 actor,
3233 descendants_only,
3334 recursive,
34-
35+
3536 // internal use only - not for clients
3637 ignore_not_empty,
3738
@@ -48,12 +49,12 @@ class LLRmDir extends LLFilesystemOperation {
4849 this . checkpoint ( 'remove :: access control' ) ;
4950
5051 // Check write access to target
51- if ( ! await svc_acl . check ( actor , target , 'write' ) ) {
52+ if ( ! await svc_acl . check ( actor , target , 'write' ) ) {
5253 throw await svc_acl . get_safe_acl_error ( actor , target , 'write' ) ;
5354 }
5455 }
5556
56- if ( await target . get ( 'immutable' ) && ! descendants_only ) {
57+ if ( await target . get ( 'immutable' ) && ! descendants_only ) {
5758 throw APIError . create ( 'immutable' ) ;
5859 }
5960
@@ -64,20 +65,20 @@ class LLRmDir extends LLFilesystemOperation {
6465 await target . get ( 'uid' )
6566 ) ;
6667
67- if ( children . length > 0 && ! recursive && ! ignore_not_empty ) {
68+ if ( children . length > 0 && ! recursive && ! ignore_not_empty ) {
6869 throw APIError . create ( 'not_empty' ) ;
6970 }
7071
7172 const tracer = svc . get ( 'traceService' ) . tracer ;
7273 const tasks = new ParallelTasks ( { tracer, max : max_tasks } ) ;
7374
74- for ( const child_uuid of children ) {
75+ for ( const child_uuid of children ) {
7576 tasks . add ( `fs:rm:rm-child` , async ( ) => {
7677 const child_node = await fs . node (
7778 new NodeUIDSelector ( child_uuid )
7879 ) ;
7980 const type = await child_node . get ( 'type' ) ;
80- if ( type === FSNodeContext . TYPE_DIRECTORY ) {
81+ if ( type === FSNodeContext . TYPE_DIRECTORY ) {
8182 const ll_rm = new LLRmDir ( ) ;
8283 await ll_rm . run ( {
8384 target : await fs . node (
@@ -102,14 +103,25 @@ class LLRmDir extends LLFilesystemOperation {
102103 }
103104
104105 await tasks . awaitAll ( ) ;
105- if ( ! descendants_only ) {
106+ if ( target . provider instanceof MemoryFSProvider ) {
106107 await target . provider . rmdir ( {
107108 context,
108109 node : target ,
109110 options : {
110- ignore_not_empty : true ,
111+ recursive,
112+ descendants_only,
111113 } ,
112114 } ) ;
115+ } else {
116+ if ( ! descendants_only ) {
117+ await target . provider . rmdir ( {
118+ context,
119+ node : target ,
120+ options : {
121+ ignore_not_empty : true ,
122+ } ,
123+ } ) ;
124+ }
113125 }
114126 }
115127}
0 commit comments