#!/bin/bash

# WSL Dotnet Cleanup - PostToolUse Hook
# Removes literal "bin\Debug" folders created by Roslyn BuildHost on WSL
# Roslyn uses Windows path separators, creating "bin\Debug" as a single folder name
# instead of the proper bin/Debug/ directory structure.

set -euo pipefail

HOOK_INPUT=$(cat)

# Quick exit: only care about Bash tool calls containing "dotnet" (~1ms)
case "$HOOK_INPUT" in
  *dotnet*) ;; # proceed to cleanup
  *) exit 0 ;; # fast exit
esac

# Find and remove corrupted bin\Debug folders (literal backslash in name)
# bin?Debug matches "bin\Debug" where ? is the literal backslash character
for d in src/*/bin?Debug bin?Debug; do
  [ -d "$d" ] && rm -rf "$d"
done

exit 0
