Skip to content

Commit

Permalink
dev: ll_move -> provider.move
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jan 10, 2025
1 parent 28c5800 commit 7293fdb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
37 changes: 6 additions & 31 deletions src/backend/src/filesystem/ll_operations/ll_move.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class LLMove extends LLFilesystemOperation {
}

async _run () {
const { _path } = this.modules;
const { context } = this;
const { source, parent, user, actor, target_name, metadata } = this.values;
const svc = context.get('services');
const { source, parent, actor, target_name, metadata } = this.values;

// Access Control
{
Expand All @@ -45,36 +43,13 @@ class LLMove extends LLFilesystemOperation {
}
}

const old_path = await source.get('path');

const svc_fsEntry = svc.get('fsEntryService');
const op_update = await svc_fsEntry.update(source.uid, {
...(
await source.get('parent_uid') !== await parent.get('uid')
? { parent_uid: await parent.get('uid') }
: {}
),
path: _path.join(await parent.get('path'), target_name),
name: target_name,
...(metadata ? { metadata } : {}),
});

source.entry.name = target_name;
source.entry.path = _path.join(await parent.get('path'), target_name);

await op_update.awaitDone();

const svc_fs = svc.get('filesystem');
await svc_fs.update_child_paths(old_path, source.entry.path, user.id);

const svc_event = svc.get('event');

await svc_event.emit('fs.move.file', {
await source.provider.move({
context: this.context,
moved: source,
old_path,
node: source,
new_parent: parent,
new_name: target_name,
metadata,
});

return source;
}
}
Expand Down
43 changes: 43 additions & 0 deletions src/backend/src/modules/puterfs/lib/PuterFSProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,49 @@ class PuterFSProvider extends putility.AdvancedBase {
return child_uuids;
}

async move ({ context, node, new_parent, new_name, metadata }) {
const { _path } = this.modules;

const services = context.get('services');
const old_path = await node.get('path');
const new_path = _path.join(await new_parent.get('path'), new_name);

const svc_fsEntry = services.get('fsEntryService');
const op_update = await svc_fsEntry.update(node.uid, {
...(
await node.get('parent_uid') !== await new_parent.get('uid')
? { parent_uid: await new_parent.get('uid') }
: {}
),
path: new_path,
name: new_name,
...(metadata ? { metadata } : {}),
});

node.entry.name = new_name;
node.entry.path = new_path;

// NOTE: this is a safeguard passed to update_child_paths to isolate
// changes to the owner's directory tree, ut this may need to be
// removed in the future.
const user_id = await node.get('user_id');

await op_update.awaitDone();

const svc_fs = services.get('filesystem');
await svc_fs.update_child_paths(old_path, node.entry.path, user_id);

const svc_event = services.get('event');

await svc_event.emit('fs.move.file', {
context,
moved: node,
old_path,
});

return node;
}

async copy_tree ({ context, source, parent, target_name }) {
return await this.copy_tree_(
{ context, source, parent, target_name });
Expand Down

0 comments on commit 7293fdb

Please sign in to comment.