refactor(app-scan): auto-clean leftover folders, drop bogus wipe prompt

The empty-folder reaper only ever fired on folders with no real data
(empty, or only a regenerable .config and/or migrate.txt marker), yet
prompted 'THIS WILL WIPE ALL DATA' before each removal — a question
about data that didn't exist. Collapse the four duplicated branches into
one reason-string path, clean these leftovers automatically, and fix the
stale $app_name used in the DB-delete (it deleted the wrong row when
looping over $folder_name).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
librelad 2026-05-29 14:53:41 +01:00
parent b1ffe9d052
commit ad08ce2324

View File

@ -112,94 +112,44 @@ databaseAppScan()
checkSuccess "All apps are up to date."
fi
# Check and uninstall apps that contain only a config file, are empty, have only a migrate.txt file, or both
# Reap leftover app folders that hold no real data: completely empty, or
# holding only the regenerable .config and/or the migrate.txt marker. There
# is nothing to lose in any of these cases, so we clean them automatically
# rather than prompting — the old "WIPE ALL DATA" question fired precisely
# when there was no data to wipe.
for folder_name in $folder_names; do
if [[ "$folder_name" != "libreportal" ]]; then
folder_path="$containers_dir/$folder_name"
if [ -d "$folder_path" ]; then
local num_files=$(runFileOp find "$folder_path" -maxdepth 1 -type f | wc -l)
[[ "$folder_name" == "libreportal" ]] && continue
local folder_path="$containers_dir/$folder_name"
# Check if the folder is empty, contains only a config file, has only a migrate.txt file, or contains both
if [ "$num_files" -eq 0 ]; then
isNotice "Uninstalling $folder_name because it is empty."
if [[ "$CFG_REQUIREMENT_AUTO_CLEAN_FOLDERS" != "true" ]]; then
while true; do
echo ""
isQuestion "Would you like to remove $folder_name? *THIS WILL WIPE ALL DATA* (y/n): "
read -p "" found_empty_remove_choice
if [[ -n "$found_empty_remove_choice" ]]; then
break
fi
isNotice "Please provide a valid input."
done
if [[ "$found_empty_remove_choice" == [yY] ]]; then
dockerUninstallApp "$folder_name";
fi
else
dockerUninstallApp "$folder_name";
fi
elif [ "$num_files" -eq 1 ] && [ -f "$folder_path/$folder_name.config" ]; then
isNotice "Uninstalling $folder_name because it contains only a config file."
if [[ "$CFG_REQUIREMENT_AUTO_CLEAN_FOLDERS" != "true" ]]; then
while true; do
echo ""
isQuestion "Would you like to remove $folder_name? *THIS WILL WIPE ALL DATA* (y/n): "
read -p "" found_empty_remove_choice
if [[ -n "$found_empty_remove_choice" ]]; then
break
fi
isNotice "Please provide a valid input."
done
if [[ "$found_empty_remove_choice" == [yY] ]]; then
dockerUninstallApp "$folder_name";
fi
else
dockerUninstallApp "$folder_name";
fi
elif [ "$num_files" -eq 1 ] && [ -f "$folder_path/migrate.txt" ]; then
isNotice "Uninstalling $folder_name because it contains only a migrate.txt file."
if [[ "$CFG_REQUIREMENT_AUTO_CLEAN_FOLDERS" != "true" ]]; then
while true; do
echo ""
isQuestion "Would you like to remove $folder_name? *THIS WILL WIPE ALL DATA* (y/n): "
read -p "" found_empty_remove_choice
if [[ -n "$found_empty_remove_choice" ]]; then
break
fi
isNotice "Please provide a valid input."
done
if [[ "$found_empty_remove_choice" == [yY] ]]; then
dockerUninstallApp "$folder_name";
fi
else
dockerUninstallApp "$folder_name";
fi
elif [ "$num_files" -eq 2 ] && [ -f "$folder_path/$folder_name.config" ] && [ -f "$folder_path/migrate.txt" ]; then
isNotice "Uninstalling $folder_name because it contains both a config file and a migrate.txt file."
if [[ "$CFG_REQUIREMENT_AUTO_CLEAN_FOLDERS" != "true" ]]; then
while true; do
echo ""
isQuestion "Would you like to remove $folder_name? *THIS WILL WIPE ALL DATA* (y/n): "
read -p "" found_empty_remove_choice
if [[ -n "$found_empty_remove_choice" ]]; then
break
fi
isNotice "Please provide a valid input."
done
if [[ "$found_empty_remove_choice" == [yY] ]]; then
dockerUninstallApp "$folder_name";
fi
else
dockerUninstallApp "$folder_name";
fi
fi
else
# If the folder doesn't exist in the directory, uninstall it from the database
isNotice "Folder $folder_name does not exist. Removing from the Database."
local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "DELETE FROM apps WHERE name = '$folder_name';")
if [ ! -d "$folder_path" ]; then
isNotice "Folder $folder_name no longer exists — removing it from the database."
runInstallOp sqlite3 "$docker_dir/$db_file" "DELETE FROM apps WHERE name = '$folder_name';"
checkSuccess "Removing $folder_name from the apps database."
((updated_count++)) # Increment updated_count
((updated_count++))
continue
fi
local num_files=$(runFileOp find "$folder_path" -maxdepth 1 -type f | wc -l)
local has_config=false has_migrate=false
[ -f "$folder_path/$folder_name.config" ] && has_config=true
[ -f "$folder_path/migrate.txt" ] && has_migrate=true
# Describe why the folder counts as a no-data leftover (empty string =
# it has real content, so leave it alone).
local reason=""
if [ "$num_files" -eq 0 ]; then
reason="empty"
elif [ "$num_files" -eq 1 ] && $has_config; then
reason="only a config file"
elif [ "$num_files" -eq 1 ] && $has_migrate; then
reason="only a migrate.txt marker"
elif [ "$num_files" -eq 2 ] && $has_config && $has_migrate; then
reason="only a config file and a migrate.txt marker"
fi
if [[ -n "$reason" ]]; then
isNotice "Cleaning up $folder_name ($reason — no data to lose)."
dockerUninstallApp "$folder_name"
fi
done
}