From 3af84c06470d482ae80246eef2c96b9e192cc94a Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 15 Sep 2025 18:24:48 -0400 Subject: [PATCH] fix: is_empty sometimes being wrong is_empty wasn't working correctly while running concurrently with fetchEntry because because the check in fetchIsEmpty was too specific. This commit fixes this issue while also adding support for a 'path' parameter to is_empty. --- src/backend/src/filesystem/FSNodeContext.js | 10 ++++---- src/backend/src/helpers.js | 27 +++++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/backend/src/filesystem/FSNodeContext.js b/src/backend/src/filesystem/FSNodeContext.js index 311e045f..26b19761 100644 --- a/src/backend/src/filesystem/FSNodeContext.js +++ b/src/backend/src/filesystem/FSNodeContext.js @@ -534,11 +534,11 @@ module.exports = class FSNodeContext { } async fetchIsEmpty () { - if ( ! this.entry ) return; - if ( ! this.entry.is_dir ) return; - if ( ! this.uid ) return; - - this.entry.is_empty = await is_empty(this.uid); + if ( ! this.uid && ! this.path ) return; + this.entry.is_empty = await is_empty({ + uid: this.uid, + path: this.path, + }); } async fetchAll(fsEntryFetcher, user, force) { diff --git a/src/backend/src/helpers.js b/src/backend/src/helpers.js index 1740dcb9..3f9e23a7 100644 --- a/src/backend/src/helpers.js +++ b/src/backend/src/helpers.js @@ -38,12 +38,29 @@ const tmp_provide_services = async ss => { async function is_empty(dir_uuid){ /** @type BaseDatabaseAccessService */ const db = services.get('database').get(DB_READ, 'filesystem'); + + let rows; - // first check if this entry is shared - let rows = await db.read( - `SELECT EXISTS(SELECT 1 FROM fsentries WHERE parent_uid = ? LIMIT 1) AS not_empty`, - [dir_uuid] - ); + if ( typeof dir_uuid === 'object' ) { + if ( typeof dir_uuid.path === 'string' && dir_uuid.path !== '' ) { + console.log('it is the path branch'); + rows = await db.read( + `SELECT EXISTS(SELECT 1 FROM fsentries WHERE path LIKE ${db.case({ + sqlite: `? || '%'`, + otherwise: `CONCAT(?, '%')`, + })} LIMIT 1) AS not_empty`, + [dir_uuid.path + '/'] + ); + } else dir_uuid = dir_uuid.uid; + } + + if ( typeof dir_uuid === 'string' ) { + console.log('it is the uuid branchj'); + rows = await db.read( + `SELECT EXISTS(SELECT 1 FROM fsentries WHERE parent_uid = ? LIMIT 1) AS not_empty`, + [dir_uuid] + ); + } return !rows[0].not_empty; }