From d3881f24409d9d91904efe63a73d05dd11fdfa5f Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Thu, 13 Nov 2025 15:07:37 -0500 Subject: [PATCH] dev: decouple FSEntryFetcher by adding hasChild Adding the hasChild method of FSNodeContext as well as a corresponding method to filesystem providers is prerequisite to moving FSEntryFetcher's logic into the new puterfs extension. --- extensions/puterfs/PuterFSProvider.js | 11 +++++++++++ src/backend/src/filesystem/FSNodeContext.js | 8 ++++++++ src/backend/src/filesystem/hl_operations/hl_copy.js | 5 +---- src/backend/src/filesystem/hl_operations/hl_move.js | 5 +---- src/backend/src/filesystem/hl_operations/hl_write.js | 4 +--- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/extensions/puterfs/PuterFSProvider.js b/extensions/puterfs/PuterFSProvider.js index ddcf622a2..7488ff408 100644 --- a/extensions/puterfs/PuterFSProvider.js +++ b/extensions/puterfs/PuterFSProvider.js @@ -614,6 +614,17 @@ export default class PuterFSProvider { return child_uuids; } + async directory_has_name ({ parent, name }) { + const uid = await parent.get('uid'); + /* eslint-disable */ + let check_dupe = await db.read( + 'SELECT `id` FROM `fsentries` WHERE `parent_uid` = ? AND name = ? LIMIT 1', + [uid, name], + ); + /* eslint-enable */ + return !!check_dupe[0]; + } + /** * Write a new file to the filesystem. Throws an error if the destination * already exists. diff --git a/src/backend/src/filesystem/FSNodeContext.js b/src/backend/src/filesystem/FSNodeContext.js index 5aba67948..5f7e0fa69 100644 --- a/src/backend/src/filesystem/FSNodeContext.js +++ b/src/backend/src/filesystem/FSNodeContext.js @@ -614,6 +614,10 @@ module.exports = class FSNodeContext { } if ( key === 'uid' ) { + const uidSelector = this.get_selector_of_type(NodeUIDSelector); + if ( uidSelector ) { + return uidSelector.value; + } await this.fetchEntry(); return this.uid; } @@ -737,6 +741,10 @@ module.exports = class FSNodeContext { return await this.fs.node(new NodeChildSelector(this.selector, name)); } + + async hasChild(name) { + return await this.provider.directory_has_name({ parent: this, name }); + } async getTarget() { await this.fetchEntry(); diff --git a/src/backend/src/filesystem/hl_operations/hl_copy.js b/src/backend/src/filesystem/hl_operations/hl_copy.js index 000ba5f3c..22d5ad758 100644 --- a/src/backend/src/filesystem/hl_operations/hl_copy.js +++ b/src/backend/src/filesystem/hl_operations/hl_copy.js @@ -173,14 +173,11 @@ class HLCopy extends HLFilesystemOperation { } if ( values.dedupe_name ) { - const fsEntryFetcher = context.get('services').get('fsEntryFetcher'); const target_ext = _path.extname(target_name); const target_noext = _path.basename(target_name, target_ext); for ( let i=1 ;; i++ ) { const try_new_name = `${target_noext} (${i})${target_ext}`; - const exists = await fsEntryFetcher.nameExistsUnderParent( - parent.uid, try_new_name - ); + const exists = await parent.hasChild(try_new_name); if ( ! exists ) { target_name = try_new_name; break; diff --git a/src/backend/src/filesystem/hl_operations/hl_move.js b/src/backend/src/filesystem/hl_operations/hl_move.js index ecbe65942..354030abb 100644 --- a/src/backend/src/filesystem/hl_operations/hl_move.js +++ b/src/backend/src/filesystem/hl_operations/hl_move.js @@ -152,14 +152,11 @@ class HLMove extends HLFilesystemOperation { } if ( values.dedupe_name ) { - const svc_fsEntryFetcher = svc.get('fsEntryFetcher'); const target_ext = _path.extname(target_name); const target_noext = _path.basename(target_name, target_ext); for ( let i=1 ;; i++ ) { const try_new_name = `${target_noext} (${i})${target_ext}`; - const exists = await svc_fsEntryFetcher.nameExistsUnderParent( - parent.uid, try_new_name - ); + const exists = await parent.hasChild(try_new_name); if ( ! exists ) { target_name = try_new_name; break; diff --git a/src/backend/src/filesystem/hl_operations/hl_write.js b/src/backend/src/filesystem/hl_operations/hl_write.js index b89eabe8a..cea9aad6f 100644 --- a/src/backend/src/filesystem/hl_operations/hl_write.js +++ b/src/backend/src/filesystem/hl_operations/hl_write.js @@ -251,9 +251,7 @@ class HLWrite extends HLFilesystemOperation { const target_noext = _path.basename(target_name, target_ext); for ( let i=1 ;; i++ ) { const try_new_name = `${target_noext} (${i})${target_ext}`; - const exists = await fsEntryFetcher.nameExistsUnderParent( - parent.uid, try_new_name - ); + const exists = await parent.hasChild(try_new_name); if ( ! exists ) { target_name = try_new_name; break;