Add core userdata backup option to post_update and give user option to exit update process if backup fails

This commit is contained in:
icenine451 2025-03-26 11:07:45 -04:00
parent 2004cc7a3e
commit fafba97ad4

View file

@ -17,47 +17,65 @@ post_update() {
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --text="Would you like to backup some or all of the RetroDECK userdata prior to update?\n\nIf you choose \"Backup Core Userdata\" only irreplaceable files (like saves, states and gamelists) will be backed up. If you choose \"Backup Some Userdata\" you will be given a choice of which folders to backup.\n\nIf you choose \"Backup All Userdata\" then ALL data (including ROMs and downloaded media) will be backed up.\nPLEASE NOTE: A full backup may take up a large amount of space, especially if you have a lot of scraped media.") --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --text="Would you like to backup some or all of the RetroDECK userdata prior to update?\n\nIf you choose \"Backup Core Userdata\" only irreplaceable files (like saves, states and gamelists) will be backed up. If you choose \"Backup Some Userdata\" you will be given a choice of which folders to backup.\n\nIf you choose \"Backup All Userdata\" then ALL data (including ROMs and downloaded media) will be backed up.\nPLEASE NOTE: A full backup may take up a large amount of space, especially if you have a lot of scraped media.")
local rc=$? local rc=$?
if [[ $rc == "0" ]] && [[ -z "$choice" ]]; then # User selected No Backup button if [[ $rc == "0" ]] && [[ -z "$choice" ]]; then # User selected No Backup button
log i "User chose to not backup prior to update." log i "User chose to not backup prior to update."
else else
case $choice in case $choice in
"Backup Core Userdata" ) "Backup Core Userdata" )
log i "User chose to backup core userdata prior to update." log i "User chose to backup core userdata prior to update."
backup_retrodeck_userdata "core" if ! backup_retrodeck_userdata "core"; then
;; log d "Userdata backup failed, giving option to proceed"
"Backup Some Userdata" ) if [[ $(configurator_generic_question_dialog "RetroDECK Update" "Unfortunately the userdata backup process was not successful.\nWould you like to proceed with the upgrade anyway?\n\nRetroDECK will exit if you choose \"No\"") == "false" ]]; then
log i "User chose to backup some userdata prior to update." log d "User chose to stop post_update process after backup failure"
while read -r config_line; do exit 1
local current_setting_name=$(get_setting_name "$config_line" "retrodeck") fi
if [[ ! $current_setting_name =~ (rdhome|sdcard|backups_folder) ]]; then # Ignore these locations fi
log d "Adding $current_setting_name to compressible paths." ;;
local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths") "Backup Some Userdata" )
compressible_paths=("${compressible_paths[@]}" "false" "$current_setting_name" "$current_setting_value") log i "User chose to backup some userdata prior to update."
fi while read -r config_line; do
done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f') local current_setting_name=$(get_setting_name "$config_line" "retrodeck")
if [[ ! $current_setting_name =~ (rdhome|sdcard|backups_folder) ]]; then # Ignore these locations
log d "Adding $current_setting_name to compressible paths."
local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths")
compressible_paths=("${compressible_paths[@]}" "false" "$current_setting_name" "$current_setting_value")
fi
done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f')
choice=$(rd_zenity \ choice=$(rd_zenity \
--list --width=1200 --height=720 \ --list --width=1200 --height=720 \
--checklist \ --checklist \
--separator="^" \ --separator="^" \
--print-column=3 \ --print-column=3 \
--text="Please select folders to compress..." \ --text="Please select folders to compress..." \
--column "Backup?" \ --column "Backup?" \
--column "Folder Name" \ --column "Folder Name" \
--column "Path" \ --column "Path" \
"${compressible_paths[@]}") "${compressible_paths[@]}")
choices=() # Expand choice string into passable array choices=() # Expand choice string into passable array
IFS='^' read -ra choices <<< "$choice" IFS='^' read -ra choices <<< "$choice"
backup_retrodeck_userdata "custom" "${choices[@]}" # Expand array of choices into individual arguments if ! backup_retrodeck_userdata "custom" "${choices[@]}"; then # Expand array of choices into individual arguments
;; log d "Userdata backup failed, giving option to proceed"
"Backup All Userdata" ) if [[ $(configurator_generic_question_dialog "RetroDECK Update" "Unfortunately the userdata backup process was not successful.\nWould you like to proceed with the upgrade anyway?\n\nRetroDECK will exit if you choose \"No\"") == "false" ]]; then
log i "User chose to backup all userdata prior to update." log d "User chose to stop post_update process after backup failure"
backup_retrodeck_userdata "complete" exit 1
;; fi
esac fi
fi ;;
"Backup All Userdata" )
log i "User chose to backup all userdata prior to update."
if ! backup_retrodeck_userdata "complete"; then
log d "Userdata backup failed, giving option to proceed"
if [[ $(configurator_generic_question_dialog "RetroDECK Update" "Unfortunately the userdata backup process was not successful.\nWould you like to proceed with the upgrade anyway?\n\nRetroDECK will exit if you choose \"No\"") == "false" ]]; then
log d "User chose to stop post_update process after backup failure"
exit 1
fi
fi
;;
esac
fi
# Start of post_update actions # Start of post_update actions