From 43a0be33ca975e17528c311efce5c58d7eedf4de Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Fri, 12 Sep 2025 16:59:47 -0400 Subject: [PATCH] fix: selector handling from 8cfa0ece For instances where svc_fs.node was called and explicitly passed a NodePathSelector (instead of being passed a legacy-style object with a path attribute) this code was failing. This commit moves the affected code snippet after input coercion and updates references to use the coerced input. style: formatting changes were applied to the code. Instead of using nested conditional blocks we use labelled breaks --- .../src/filesystem/FilesystemService.js | 69 ++++++++----------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/src/backend/src/filesystem/FilesystemService.js b/src/backend/src/filesystem/FilesystemService.js index 7e86862c..4ca5bbbf 100644 --- a/src/backend/src/filesystem/FilesystemService.js +++ b/src/backend/src/filesystem/FilesystemService.js @@ -328,48 +328,8 @@ class FilesystemService extends BaseService { selector = new NodePathSelector(selector); } } - else if ( typeof selector.path === 'string' ) { - // other system directories - if ( selector.path.startsWith('/')) { - // OPTIMIZATION: Check if the path matches a system directory pattern. - const systemDirRegex = /^\/([a-zA-Z0-9_]+)\/(Trash|AppData|Desktop|Documents|Pictures|Videos|Public)$/; - const match = selector.path.match(systemDirRegex); - if (match) { - const username = match[1]; - const dirName = match[2]; - - // Get the user object (this is likely cached). - const user = await get_user({ username }); - - if (user) { - let uuidKey = `${dirName.toLowerCase()}_uuid`; // e.g., 'desktop_uuid' - // Home directory - if(selector.path === '/' + user.username) { - uuidKey = 'home_uuid'; - } - const cachedUUID = user[uuidKey]; - - if (cachedUUID) { - // If we have a cached UUID, use it for a direct lookup! - selector = new NodeUIDSelector(cachedUUID); - } else { - // Fallback if the UUID isn't on the user object for some reason. - selector = new NodePathSelector(selector.path); - } - } else { - // User not found, proceed with normal path resolution. - selector = new NodePathSelector(selector.path); - } - } else { - selector = new NodePathSelector(selector.path); - } - } else { - selector = new NodePathSelector(selector.path); - } - } - - // TEMP: remove when these objects aren't used anymore + // COERCE: legacy selection objects to Node*Selector objects if ( typeof selector === 'object' && selector.constructor.name === 'Object' @@ -384,6 +344,33 @@ class FilesystemService extends BaseService { } } + system_dir_check: { + if ( ! (selector instanceof NodePathSelector) ) break system_dir_check; + if ( ! selector.value.startsWith('/')) break system_dir_check; + + // OPTIMIZATION: Check if the path matches a system directory pattern. + const systemDirRegex = /^\/([a-zA-Z0-9_]+)\/(Trash|AppData|Desktop|Documents|Pictures|Videos|Public)$/; + const match = selector.value.match(systemDirRegex); + if ( ! match ) break system_dir_check; + + const username = match[1]; + const dirName = match[2]; + + // Get the user object (this is likely cached). + const user = await get_user({ username }); + if ( ! user ) break system_dir_check; + + let uuidKey = ( selector.value === '/' + user.username ) + ? 'home_uuid' + : `${dirName.toLowerCase()}_uuid`; // e.g., 'desktop_uuid' + + const cachedUUID = user[uuidKey]; + if ( ! cachedUUID ) break system_dir_check; + + // If we have a cached ID, use it for more direct lookup. + selector = new NodeUIDSelector(cachedUUID); + } + const svc_mountpoint = this.services.get('mountpoint'); const provider = await svc_mountpoint.get_provider(selector);