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:
parent
b1ffe9d052
commit
ad08ce2324
@ -112,94 +112,44 @@ databaseAppScan()
|
|||||||
checkSuccess "All apps are up to date."
|
checkSuccess "All apps are up to date."
|
||||||
fi
|
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
|
for folder_name in $folder_names; do
|
||||||
if [[ "$folder_name" != "libreportal" ]]; then
|
[[ "$folder_name" == "libreportal" ]] && continue
|
||||||
folder_path="$containers_dir/$folder_name"
|
local folder_path="$containers_dir/$folder_name"
|
||||||
if [ -d "$folder_path" ]; then
|
|
||||||
local num_files=$(runFileOp find "$folder_path" -maxdepth 1 -type f | wc -l)
|
|
||||||
|
|
||||||
# Check if the folder is empty, contains only a config file, has only a migrate.txt file, or contains both
|
if [ ! -d "$folder_path" ]; then
|
||||||
if [ "$num_files" -eq 0 ]; then
|
isNotice "Folder $folder_name no longer exists — removing it from the database."
|
||||||
isNotice "Uninstalling $folder_name because it is empty."
|
runInstallOp sqlite3 "$docker_dir/$db_file" "DELETE FROM apps WHERE name = '$folder_name';"
|
||||||
if [[ "$CFG_REQUIREMENT_AUTO_CLEAN_FOLDERS" != "true" ]]; then
|
checkSuccess "Removing $folder_name from the apps database."
|
||||||
while true; do
|
((updated_count++))
|
||||||
echo ""
|
continue
|
||||||
isQuestion "Would you like to remove $folder_name? *THIS WILL WIPE ALL DATA* (y/n): "
|
fi
|
||||||
read -p "" found_empty_remove_choice
|
|
||||||
if [[ -n "$found_empty_remove_choice" ]]; then
|
local num_files=$(runFileOp find "$folder_path" -maxdepth 1 -type f | wc -l)
|
||||||
break
|
local has_config=false has_migrate=false
|
||||||
fi
|
[ -f "$folder_path/$folder_name.config" ] && has_config=true
|
||||||
isNotice "Please provide a valid input."
|
[ -f "$folder_path/migrate.txt" ] && has_migrate=true
|
||||||
done
|
|
||||||
if [[ "$found_empty_remove_choice" == [yY] ]]; then
|
# Describe why the folder counts as a no-data leftover (empty string =
|
||||||
dockerUninstallApp "$folder_name";
|
# it has real content, so leave it alone).
|
||||||
fi
|
local reason=""
|
||||||
else
|
if [ "$num_files" -eq 0 ]; then
|
||||||
dockerUninstallApp "$folder_name";
|
reason="empty"
|
||||||
fi
|
elif [ "$num_files" -eq 1 ] && $has_config; then
|
||||||
elif [ "$num_files" -eq 1 ] && [ -f "$folder_path/$folder_name.config" ]; then
|
reason="only a config file"
|
||||||
isNotice "Uninstalling $folder_name because it contains only a config file."
|
elif [ "$num_files" -eq 1 ] && $has_migrate; then
|
||||||
if [[ "$CFG_REQUIREMENT_AUTO_CLEAN_FOLDERS" != "true" ]]; then
|
reason="only a migrate.txt marker"
|
||||||
while true; do
|
elif [ "$num_files" -eq 2 ] && $has_config && $has_migrate; then
|
||||||
echo ""
|
reason="only a config file and a migrate.txt marker"
|
||||||
isQuestion "Would you like to remove $folder_name? *THIS WILL WIPE ALL DATA* (y/n): "
|
fi
|
||||||
read -p "" found_empty_remove_choice
|
|
||||||
if [[ -n "$found_empty_remove_choice" ]]; then
|
if [[ -n "$reason" ]]; then
|
||||||
break
|
isNotice "Cleaning up $folder_name ($reason — no data to lose)."
|
||||||
fi
|
dockerUninstallApp "$folder_name"
|
||||||
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';")
|
|
||||||
checkSuccess "Removing $folder_name from the apps database."
|
|
||||||
((updated_count++)) # Increment updated_count
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user