#!/usr/bin/env bash
# W10 IR-150 teardown: inbound sweep, three numbers BEFORE rm, rm target subtree, free after.
cd /c/Users/decid/Documents/projects/spt-core/.worktrees/w10-busy || exit 9
S="C:/Users/decid/AppData/Local/Temp/claude/C--Users-decid-Documents-projects-spt-core/cf4213ed-2bda-42a2-a018-1a54d595cb80/scratchpad"
F="$S/w10-teardown.log"
free() { powershell -NoProfile -Command "(Get-PSDrive C).Free"; }
{
echo "inbound: $(powershell -NoProfile -Command "(Get-ChildItem C:\\Users\\decid\\Documents\\projects\\spt-core\\.worktrees -Directory -Depth 1 -Force -ErrorAction SilentlyContinue | Where-Object { \$_.Attributes -match 'ReparsePoint' -and ((\$_.Target -join ',') -match 'w10-busy') } | Measure-Object).Count")"
echo "measure_start $(date -u +%FT%TZ)"
echo "apparent: $(du -sb --apparent-size target | cut -f1)"
echo "allocated: $(du -sB1 target | cut -f1)"
echo "escaped (inodes bytes): $(find target -type f -links +1 -printf '%i %n %s\n' | sort | uniq -c | awk '$1 < $3 { n++; b += $4 } END { print n+0, b+0 }')"
echo "free_before $(date -u +%FT%TZ): $(free)"
rm -rf target; echo "RM=$?"
ls -d target 2>&1
echo "free_after $(date -u +%FT%TZ): $(free)"
} > "$F" 2>&1
