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 / Sources / RemoteIndex.swift

15 lines · 1487 bytes Raw Blame History
1/// The shell command that rebuilds a machine's file list in ~/.cache/hop as shards (Remote.refreshIndex runs it there
2/// under nohup). `roots` and `prune` come already quoted for the shell. Checked on Linux by tools/check-index-rebuild.sh.
3enum RemoteIndex {
4 static func build(roots: String, prune: String, shards: Int) -> String {
5 // find exits 1 for every error it reports and walks on. Folders it may not read (root's or another user's
6 // data under a root) and files that vanish during the walk still leave a list worth having, so keep it then.
7 // Any other message (a write error when the disk fills) or a worse exit (killed, 2+) throws the list away.
8 // Before, any exit but 0 threw it away, the shards never installed and every refresh started over (L1290).
9 "cd ~/.cache/hop && LC_ALL=C find \(roots) -xdev \\( -path '*/.*' -o \(prune) \\) -prune -o -type d -printf '%p/\\n' -o -printf '%p\\n' " +
10 "> index.tmp 2> index.err; c=$?; { [ $c -eq 0 ] || { [ $c -eq 1 ] && ! LC_ALL=C grep -qv -e ': Permission denied$' -e ': No such file or directory$' index.err; }; } " +
11 "&& [ -s index.tmp ] && rm -rf shards.new && mkdir shards.new && split -n l/\(shards) -d -a 2 index.tmp shards.new/s " +
12 "&& rm -f index.tmp index.txt && rm -rf shards.old && { [ ! -d shards ] || mv shards shards.old; } && mv shards.new shards && rm -rf shards.old; " +
13 "rm -f index.tmp index.err; rmdir ~/.cache/hop/building"
14 }
15}