From 03a6473d5a30e5213e4cfdab1c2487611be452b4 Mon Sep 17 00:00:00 2001 From: Arlind Date: Sun, 23 Nov 2025 16:09:52 +0100 Subject: [PATCH] Update .gitea/actions/cleanup/action.yml --- .gitea/actions/cleanup/action.yml | 68 ++++++++++--------------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/.gitea/actions/cleanup/action.yml b/.gitea/actions/cleanup/action.yml index de75287..b6ea0a6 100644 --- a/.gitea/actions/cleanup/action.yml +++ b/.gitea/actions/cleanup/action.yml @@ -21,60 +21,46 @@ runs: exit 1 fi - # Load all skins from JSON readarray -t skins < <(jq -r '.[]' "$all_skins_file") - # Remove known stray files - [ -f how-to-use.md ] && rm -f how-to-use.md - [ -f src/replay.osr ] && rm -f src/replay.osr - [ -d src/default-skin ] && rm -rf src/default-skin + [ -f how-to-use.md ] && rm -f -- how-to-use.md + [ -f src/replay.osr ] && rm -f -- src/replay.osr + [ -d src/default-skin ] && rm -rf -- src/default-skin - ############################################################ - # 1. Normalization for matching (lenient, consistent) - ############################################################ - normalize() { - printf "%s" "$1" | \ - tr '[:upper:]' '[:lower:]' | \ - sed 's/[][{}()<>|\/:*?"'"'"' ]/-/g' | \ - tr -s '-' | sed 's/^-//; s/-$//' + sanitize_filename() { + echo "$1" | \ + tr -d '\000-\037' | \ + sed -e 's#[][\/:*?"<>|]#-#g' | \ + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' } skins_raw=() - skins_norm=() + skins_clean=() for s in "${skins[@]}"; do skins_raw+=("$s") - skins_norm+=("$(normalize "$s")") + skins_clean+=("$(sanitize_filename "$s")") done - ############################################################ - # 2. Matching logic — FIXED (no false deletions) - ############################################################ is_known_skin() { local name="$1" - local norm="$(normalize "$name")" - - for i in "${!skins_norm[@]}"; do - [[ "$norm" == "${skins_norm[$i]}" ]] && return 0 + for i in "${!skins_raw[@]}"; do + if [[ "$name" == "${skins_raw[$i]}" ]] || [[ "$name" == "${skins_clean[$i]}" ]]; then + return 0 + fi done - return 1 } - ############################################################ - # 3. Pruning helper (unchanged except matching logic) - ############################################################ prune_dir() { local root="$1" local skin_raw="$2" local expected="$3" - # Remove unexpected root-level files for f in "$root"/*; do [ -f "$f" ] || continue basename_f="$(basename "$f")" - # Root-level filename must be exactly one of the skins if printf '%s\n' "${skins_raw[@]}" | grep -Fxq -- "$basename_f"; then continue fi @@ -83,7 +69,6 @@ runs: rm -f -- "$f" done - # Now prune inside each skin directory local folder="$root/$skin_raw" [ -d "$folder" ] || return @@ -96,44 +81,33 @@ runs: done } - ############################################################ - # 4. Remove directories for skins that do not exist anymore - ############################################################ for root in "$REPO_SCREENSHOT_DIR" "$REPO_RANKING_PANEL_DIR" "$REPO_MOD_ICONS_DIR" "$REPO_THUMBNAIL_DIR" "$OSK_PATH" "$DOC_DIR"; do [ -d "$root" ] || continue - for dir in "$root"/*; do [ -d "$dir" ] || continue name="$(basename "$dir")" if ! is_known_skin "$name"; then - echo " → Skin '$name' deleted — removing $dir" + echo " → Skin '$name' deleted—removing directory $dir" rm -rf -- "$dir" || true fi done done - ############################################################ - # 5. Expected filenames must use RAW names — FIXED - ############################################################ for idx in "${!skins_raw[@]}"; do skin="${skins_raw[$idx]}" + header="${skins_clean[$idx]}" - # Expected base filename = RAW name (FIX) - header="$skin" - - # Override using skin.ini if available ini=$(find "$DANSER_SKINS_DIR/$skin" -maxdepth 1 -type f -iname "skin.ini" -print -quit || true) if [[ -f "$ini" ]]; then - ini_raw=$(grep -i '^[[:space:]]*Name:' "$ini" | head -n1 || true) - ini_raw="${ini_raw#*:}" - ini_raw="$(echo "$ini_raw" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')" + raw=$(grep -i '^[[:space:]]*Name:' "$ini" | head -n1 || true) + raw="${raw#*:}" + raw="$(echo "$raw" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')" - # If INI name is not empty, use it directly as the filename - [[ -n "$ini_raw" ]] && header="$ini_raw" + tmp="$(sanitize_filename "$raw")" + [[ -n "$tmp" ]] && header="$tmp" fi - # Prune directories using expected filenames prune_dir "$REPO_SCREENSHOT_DIR" "$skin" "$header.mp4" prune_dir "$REPO_RANKING_PANEL_DIR" "$skin" "$header.webp" prune_dir "$REPO_MOD_ICONS_DIR" "$skin" "$header.webp"