interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

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.
5set -eu
6umask 077
7export LC_ALL=C
8[ "$#" = 1 ] || { echo 'usage: policy.sh REMOVE < replacement-policy' >&2; exit 2; }
9remove=$1
10parent=$(CDPATH= cd -- "$(dirname -- "$remove")" && pwd -P)
11remove=$parent/$(basename -- "$remove")
12work=$(mktemp -d "$parent/.research-policy.XXXXXXXX")
13trap 'rm -rf "$work"' EXIT
14trap 'exit 1' HUP INT TERM
15# Read at most one byte beyond the policy boundary; overflow never replaces the old file.
16head -c 65536 > "$work/remove"
17[ "$(wc -c < "$work/remove")" -le 65535 ] || { echo 'research policy: input exceeds 65535 bytes' >&2; exit 1; }
18version=$(sha256sum < "$work/remove" | cut -d ' ' -f1)
19# The lock's inode is stable: never remove or rename REMOVE.lock.
20exec 6>>"$remove.lock"
21flock 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; }
24mv -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.
27printf 'REMOVE_REPLACED sha256=%s\n' "$version"