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
This commit is contained in:
KernelDeimos
2025-09-12 16:59:47 -04:00
parent c508189455
commit 43a0be33ca

View File

@@ -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);