Skip to content

Commit

Permalink
wip: fix logic for recursive empty folder deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobiClark committed Nov 27, 2024
1 parent f85ab9a commit f836b66
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5458,7 +5458,7 @@ window.openPage = async (targetPageID) => {
const isNonExistent = !window.fs.existsSync(filePath);

if (isNonExistent) {
console.log(`Deleting reference to non-existent file: ${currentPath}${fileName}`);
log.info(`Deleting reference to non-existent file: ${currentPath}${fileName}`);
delete files[fileName];
}
}
Expand All @@ -5472,7 +5472,6 @@ window.openPage = async (targetPageID) => {

// Start collecting non-existent files
await collectNonExistentFiles(datasetStructure);

if (nonExistentFiles.length > 0) {
await swalFileListSingleAction(
nonExistentFiles,
Expand All @@ -5488,16 +5487,15 @@ window.openPage = async (targetPageID) => {

// Purge non-existent files from the dataset structure before generating manifest files
await purgeNonExistentFilesFromDatasetStructure(window.datasetStructureJSONObj);
console.log("Purged non-existent files from dataset structure");
// Helper function to check if a folder structure is empty
const isFolderJSONObjEmpty = (folderStructure) => {
// Get the list of files and folders at this level
const fileKeys = Object.keys(folderStructure.files || {});
const folderKeys = Object.keys(folderStructure.folders || {});

// If no files and no folders exist, the folder is empty
if (fileKeys.length === 0 && folderKeys.length === 0) {
return true;
if (fileKeys.length != 0 || folderKeys.length != 0) {
return false;
}

// Recursively check each subfolder
Expand All @@ -5519,7 +5517,6 @@ window.openPage = async (targetPageID) => {

for (const folderName in folders) {
const folderStructure = folders[folderName];

// Check if the folder is empty and delete it
if (isFolderJSONObjEmpty(folderStructure)) {
delete folders[folderName];
Expand Down

0 comments on commit f836b66

Please sign in to comment.