ilusm.dev

wch

File change detection via SHA-256 digest polling - create a watcher tracking a list of file paths, poll for changes (returns a list of {path, old, cur} change records and updates internal state), add new paths to a running watcher, list all watched paths, and detect if any watched file is currently missing.

Load with: use wch

What this module does

wch detects file changes by hashing file contents with SHA-256 (cry.s25) and comparing to a stored digest. There are no OS filesystem events - you call wchpo on a schedule (e.g. every second in a loop) and it reports which files changed, were created (old == nil), or were deleted (cur == nil) since the last poll.

Quick example

use wch
use lim

w = wchne(["src/app.ilu", "config.ini"])

whl tru:
    changes = wchpo(w)
    trl.ech(changes, \(c)
        if c.cur == nil:
            prn("deleted: " + c.path)
        | if c.old == nil:
            prn("created: " + c.path)
        |
            prn("changed: " + c.path)
    )
    limsl(1000)   # poll every second

# Add more paths
w = wchad(w, ["lib/utils.ilu"])

# Check for missing files
prn(wchan(w))  # tru if any watched file is absent

Functions

Setup

wchne(paths)

Creates a new watcher for the list of file path strings. Reads the current SHA-256 digest of each existing file as the baseline. Missing files are recorded with a nil digest.

wchad(w, paths)

Adds new paths to an existing watcher, establishing their baseline digests.

Polling

wchpo(w)

Polls all watched paths. Returns a list of change records - one per changed file - of the form {path, old, cur}. old and cur are SHA-256 digest strings or nil (nil = file absent). Updates the watcher's internal state so subsequent calls only report new changes.

Inspection

wchpa(w)

Returns the list of all watched path strings.

wchan(w)

Returns tru if any watched file is currently absent from the filesystem.

Notes

  • Polling interval is caller-controlled - wch does no scheduling.
  • Requires trl, fs, cry, and eru.