interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / tools / check-index-rebuild.sh

41 lines · 2234 bytes Raw Blame History
1#!/bin/sh
2# Checks the command Hop uses to rebuild another machine's file list (Sources/RemoteIndex.swift) where it runs: on a
3# Linux machine with GNU find. Builds the command here, runs five cases there in a scratch folder under /tmp.
4# Usage: tools/check-index-rebuild.sh SSH_HOST
5set -eu
6cd "$(dirname "$0")/.."
7host=${1:?usage: tools/check-index-rebuild.sh SSH_HOST}
8work=$(mktemp -d "${TMPDIR:-/tmp}/hop-index-check.XXXXXXXX")
9trap 'rm -rf "$work"' EXIT HUP INT TERM
10sed "s#HOP_DIR#$PWD#" toolchain/overlay.yaml > "$work/overlay.yaml"
11swiftc -swift-version 5 -vfsoverlay "$work/overlay.yaml" -Xcc -ivfsoverlay -Xcc "$work/overlay.yaml" \
12 Sources/RemoteIndex.swift tests/RemoteIndexChecks.swift -o "$work/print"
13T=/tmp/hop-index-check.$$
14{
15 echo "T=$T"
16 echo "CMD=$("$work/print" "$T/root")"
17 echo "NONE=$("$work/print" "$T/missing")"
18 cat <<'REMOTE'
19set -u
20fail=0
21mkdir -p "$T/root/a" "$T/root/locked" "$T/root/node_modules/x"
22i=0; while [ $i -lt 300 ]; do : > "$T/root/a/file-with-a-long-enough-name-to-fill-the-list-$i"; i=$((i + 1)); done
23chmod 000 "$T/root/locked"
24check() { # NAME WANT(new|old) SCRIPT
25 H="$T/home-$1"; mkdir -p "$H/.cache/hop/building" "$H/.cache/hop/shards"; echo old > "$H/.cache/hop/shards/s00"
26 HOME="$H" sh -c "$3" 2>/dev/null
27 if [ "$(cat "$H/.cache/hop/shards/s00")" = old ]; then got=old; else got=new; fi
28 left=$(cd "$H/.cache/hop" && ls -d index.tmp index.err building shards.new 2>/dev/null | tr '\n' ' ')
29 if [ "$2" = new ] && ! cat "$H"/.cache/hop/shards/s* | grep -q "^$T/root/locked/\$"; then got="$got-without-locked"; fi
30 if [ "$2" = new ] && cat "$H"/.cache/hop/shards/s* | grep -q node_modules/x; then got="$got-with-pruned"; fi
31 if [ "$got" = "$2" ] && [ -z "$left" ]; then echo "PASS $1"; else echo "FAIL $1: want $2, got $got, left [$left]"; fail=1; fi
32}
33check unreadable-folder new "$CMD"
34check plain-folder new "chmod 755 '$T/root/locked'; $CMD; chmod 000 '$T/root/locked'"
35check write-error old "trap '' XFSZ; ulimit -f 4; $CMD"
36check killed-find old "ulimit -f 4; $CMD"
37check no-root old "$NONE"
38chmod 755 "$T/root/locked"; rm -rf "$T"
39[ $fail = 0 ] && echo "INDEX REBUILD PASS" || { echo "INDEX REBUILD FAIL"; exit 1; }
40REMOTE
41} | ssh -o BatchMode=yes "$host" sh -s