mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-07 05:30:31 -06:00
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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user