#!/bin/bash
# Swaps a symlink 6,000 times with `ln -sfn` while a reader checks it exists.
# Run it in an empty folder. On macOS the reader sees gaps; with GNU ln 9.7 it should not.
mkdir -p r1 r2 && ln -sfn r1 current
(for i in $(seq 1 3000); do ln -sfn r1 current; ln -sfn r2 current; done) &
swapper=$!
checks=0
missing=0
while kill -0 "$swapper" 2>/dev/null; do
  checks=$((checks + 1))
  [ -L current ] || missing=$((missing + 1))
done
echo "ln: $(command -v ln)  checks=$checks  link-missing=$missing"
