mirror of
https://github.com/HeyPuter/puter.git
synced 2026-09-24 06:05:40 +00:00
dev(puterfs): move 'move' to extension
This commit is contained in:
@@ -449,6 +449,47 @@ class PuterFSProvider {
|
||||
return node;
|
||||
}
|
||||
|
||||
async move ({ context, node, new_parent, new_name, metadata }) {
|
||||
const old_path = await node.get('path');
|
||||
const new_path = path_.join(await new_parent.get('path'), new_name);
|
||||
|
||||
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();
|
||||
|
||||
await svc_fs.update_child_paths(old_path, node.entry.path, user_id);
|
||||
|
||||
const promises = [];
|
||||
promises.push(svc_event.emit('fs.move.file', {
|
||||
context,
|
||||
moved: node,
|
||||
old_path,
|
||||
}));
|
||||
promises.push(svc_event.emit('fs.rename', {
|
||||
uid: await node.get('uid'),
|
||||
new_name,
|
||||
}));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
async #rmnode ({ node, options }) {
|
||||
// Services
|
||||
if ( !options.override_immutable && await node.get('immutable') ) {
|
||||
|
||||
@@ -112,49 +112,8 @@ class PuterFSProvider extends putility.AdvancedBase {
|
||||
}
|
||||
|
||||
async move ({ context, node, new_parent, new_name, metadata }) {
|
||||
|
||||
const old_path = await node.get('path');
|
||||
const new_path = path.join(await new_parent.get('path'), new_name);
|
||||
|
||||
const svc_fsEntry = this.#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 = this.#services.get('filesystem');
|
||||
await svc_fs.update_child_paths(old_path, node.entry.path, user_id);
|
||||
|
||||
const svc_event = this.#services.get('event');
|
||||
|
||||
const promises = [];
|
||||
promises.push(svc_event.emit('fs.move.file', {
|
||||
context,
|
||||
moved: node,
|
||||
old_path,
|
||||
}));
|
||||
promises.push(svc_event.emit('fs.rename', {
|
||||
uid: await node.get('uid'),
|
||||
new_name,
|
||||
}));
|
||||
|
||||
return node;
|
||||
console.error('This .move should not be called!');
|
||||
throw new Error('This .move should not be called!');
|
||||
}
|
||||
|
||||
async copy_tree ({ context, node, options = {} }) {
|
||||
|
||||
Reference in New Issue
Block a user