Skip to content

Commit 0cd7f43

Browse files
committed
fs/memory-provider: rmdir
1 parent 9171748 commit 0cd7f43

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/backend/src/filesystem/ll_operations/ll_rmdir.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919
const APIError = require("../../api/APIError");
20+
const { MemoryFSProvider } = require("../../modules/puterfs/customfs/MemoryFSProvider");
2021
const { ParallelTasks } = require("../../util/otelutil");
2122
const FSNodeContext = require("../FSNodeContext");
2223
const { NodeUIDSelector } = require("../node/selectors");
2324
const { LLFilesystemOperation } = require("./definitions");
2425
const { LLRmNode } = require('./ll_rmnode');
2526

2627
class 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
}

src/backend/src/modules/puterfs/customfs/MemoryFSProvider.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,39 @@ class MemoryFSProvider {
296296
async rmdir({ context, node, options = {} }) {
297297
const inner_path = this._inner_path(node.path);
298298

299-
// remove all children
299+
if ( inner_path.includes('del') ) {
300+
console.log('inner_path: ', inner_path);
301+
}
302+
303+
// for mode: non-recursive
304+
if ( ! options.recursive ) {
305+
const children = await this.readdir({ context, node });
306+
if ( children.length > 0 ) {
307+
throw APIError.create('not_empty');
308+
}
309+
}
310+
311+
// remove all descendants
300312
for ( const [other_inner_path, other_entry_uuid] of this.entriesByPath ) {
313+
if ( other_entry_uuid === node.uid ) {
314+
// skip the directory itself
315+
continue;
316+
}
317+
318+
console.log('other_inner_path: ', other_inner_path);
319+
301320
if ( other_inner_path.startsWith(inner_path) ) {
302321
this.entriesByPath.delete(other_inner_path);
303322
this.entriesByUUID.delete(other_entry_uuid);
304323
}
305324
}
306325

307-
// remove the directory itself
308-
this.entriesByPath.delete(inner_path);
309-
this.entriesByUUID.delete(node.uid);
326+
// for mode: non-descendants-only
327+
if ( ! options.descendants_only ) {
328+
// remove the directory itself
329+
this.entriesByPath.delete(inner_path);
330+
this.entriesByUUID.delete(node.uid);
331+
}
310332

311333
this._integrity_check(node);
312334
}

0 commit comments

Comments
 (0)