Update .gitea/actions/cleanup/action.yml
This commit is contained in:
@@ -21,17 +21,17 @@ runs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load skins array
|
||||
# Load all skins from JSON
|
||||
readarray -t skins < <(jq -r '.[]' "$all_skins_file")
|
||||
|
||||
# Remove known static extras
|
||||
[ -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
|
||||
# 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
|
||||
|
||||
##############################################
|
||||
# NORMALIZATION FIX — KEY TO SOLVING PROBLEM #
|
||||
##############################################
|
||||
############################################################
|
||||
# 1. Normalization for matching (lenient, consistent)
|
||||
############################################################
|
||||
normalize() {
|
||||
printf "%s" "$1" | \
|
||||
tr '[:upper:]' '[:lower:]' | \
|
||||
@@ -39,45 +39,31 @@ runs:
|
||||
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_clean=()
|
||||
skins_norm=()
|
||||
|
||||
for s in "${skins[@]}"; do
|
||||
raw="$s"
|
||||
clean="$(sanitize_filename "$s")"
|
||||
norm="$(normalize "$s")"
|
||||
|
||||
skins_raw+=("$raw")
|
||||
skins_clean+=("$clean")
|
||||
skins_norm+=("$norm")
|
||||
skins_raw+=("$s")
|
||||
skins_norm+=("$(normalize "$s")")
|
||||
done
|
||||
|
||||
##################################################
|
||||
# SAFE SKIN MATCHING → FIXES ALL FALSE DELETIONS #
|
||||
##################################################
|
||||
############################################################
|
||||
# 2. Matching logic — FIXED (no false deletions)
|
||||
############################################################
|
||||
is_known_skin() {
|
||||
local name="$1"
|
||||
local norm="$(normalize "$name")"
|
||||
|
||||
for i in "${!skins_norm[@]}"; do
|
||||
if [[ "$norm" == "${skins_norm[$i]}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
[[ "$norm" == "${skins_norm[$i]}" ]] && return 0
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
#############################################
|
||||
# PRUNE HELPERS (unchanged except matching) #
|
||||
#############################################
|
||||
############################################################
|
||||
# 3. Pruning helper (unchanged except matching logic)
|
||||
############################################################
|
||||
prune_dir() {
|
||||
local root="$1"
|
||||
local skin_raw="$2"
|
||||
@@ -88,7 +74,7 @@ runs:
|
||||
[ -f "$f" ] || continue
|
||||
basename_f="$(basename "$f")"
|
||||
|
||||
# Root-level files must exactly match one of the skins
|
||||
# Root-level filename must be exactly one of the skins
|
||||
if printf '%s\n' "${skins_raw[@]}" | grep -Fxq -- "$basename_f"; then
|
||||
continue
|
||||
fi
|
||||
@@ -97,7 +83,7 @@ runs:
|
||||
rm -f -- "$f"
|
||||
done
|
||||
|
||||
# Now prune inside per-skin directories
|
||||
# Now prune inside each skin directory
|
||||
local folder="$root/$skin_raw"
|
||||
[ -d "$folder" ] || return
|
||||
|
||||
@@ -110,40 +96,44 @@ runs:
|
||||
done
|
||||
}
|
||||
|
||||
################################################
|
||||
# DELETE DIRECTORIES THAT ARE NOT VALID SKINS #
|
||||
################################################
|
||||
############################################################
|
||||
# 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 directory $dir"
|
||||
echo " → Skin '$name' deleted — removing $dir"
|
||||
rm -rf -- "$dir" || true
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
################################################
|
||||
# FILE PRUNING FOR EACH VALID SKIN #
|
||||
################################################
|
||||
############################################################
|
||||
# 5. Expected filenames must use RAW names — FIXED
|
||||
############################################################
|
||||
for idx in "${!skins_raw[@]}"; do
|
||||
skin="${skins_raw[$idx]}"
|
||||
header="${skins_clean[$idx]}"
|
||||
|
||||
# Try reading Name from skin.ini
|
||||
# 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
|
||||
raw=$(grep -i '^[[:space:]]*Name:' "$ini" | head -n1 || true)
|
||||
raw="${raw#*:}"
|
||||
raw="$(echo "$raw" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
|
||||
ini_raw=$(grep -i '^[[:space:]]*Name:' "$ini" | head -n1 || true)
|
||||
ini_raw="${ini_raw#*:}"
|
||||
ini_raw="$(echo "$ini_raw" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
|
||||
|
||||
tmp="$(sanitize_filename "$raw")"
|
||||
[[ -n "$tmp" ]] && header="$tmp"
|
||||
# If INI name is not empty, use it directly as the filename
|
||||
[[ -n "$ini_raw" ]] && header="$ini_raw"
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user