Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/research/policy.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / research / policy.sh` 27 lines ยท 1474 bytes Raw Blame History 1 #!/bin/sh 2 # Cooperative REMOVE replacement only: bounded stdin and namespace-atomic rename under the 3 # stable REMOVE.lock also held by sync.sh from final policy read through activation. 4 # No fsync/power-loss durability claim. Raw manual editor writes are outside this protocol. 5 set -eu 6 umask 077 7 export LC_ALL=C 8 [ "$#" = 1 ] || { echo 'usage: policy.sh REMOVE < replacement-policy' >&2; exit 2; } 9 remove=$1 10 parent=$(CDPATH= cd -- "$(dirname -- "$remove")" && pwd -P) 11 remove=$parent/$(basename -- "$remove") 12 work=$(mktemp -d "$parent/.research-policy.XXXXXXXX") 13 trap 'rm -rf "$work"' EXIT 14 trap 'exit 1' HUP INT TERM 15 # Read at most one byte beyond the policy boundary; overflow never replaces the old file. 16 head -c 65536 > "$work/remove" 17 [ "$(wc -c < "$work/remove")" -le 65535 ] || { echo 'research policy: input exceeds 65535 bytes' >&2; exit 1; } 18 version=$(sha256sum < "$work/remove" | cut -d ' ' -f1) 19 # The lock's inode is stable: never remove or rename REMOVE.lock. 20 exec 6>>"$remove.lock" 21 flock 6 22 [ ! -e "$remove" ] || [ -f "$remove" ] || { echo 'research policy: target is not a regular file' >&2; exit 1; } 23 [ ! -L "$remove" ] || { echo 'research policy: target is a symlink' >&2; exit 1; } 24 mv -Tf "$work/remove" "$remove" 25 # Receipt is emitted before releasing the lock. If sync already owns the lock this acknowledgement 26 # waits for that activation; it then belongs to the next pass. A prior acknowledgement is included. 27 printf 'REMOVE_REPLACED sha256=%s\n' "$version"