#!/bin/bash

gitCleanInstallBackups()
{
    # Remove the unzipped backup_<ts>/ snapshot dirs we just rolled up, keeping
    # the .zip files themselves. `-mindepth 1 -maxdepth 1` limits to direct
    # children of $backup_install_dir; `-exec rm -rf {} +` handles dirs via
    # -r. The previous `-type f ! -name '*.zip' -o -type d ! -name '*.zip'`
    # mis-applied the -exec to only the second clause (-o binds looser than
    # the implicit -a), so it deleted every non-.zip dir under the WHOLE tree
    # while matching no files at all.
    local result; result=$(runInstallOp find "$backup_install_dir" -mindepth 1 -maxdepth 1 ! -name '*.zip' -exec rm -rf {} +)
    checkSuccess "Cleaning up install backup folders."
    local result; result=$(cd "$backup_install_dir" && find . -maxdepth 1 -type f -name '*.zip' | xargs ls -t | tail -n +6 | xargs -r rm)
    checkSuccess "Deleting old install backup and keeping the latest 5."
}