Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

watchfs

Directory watcher. It watches a path with the C_FS gclass and runs a shell command whenever a matching file changes. Handy for auto-rebuild / auto-reload loops during development.

Architecture

C_WATCHFS
    C_FS      <- filesystem watch (emits EV_FS_CHANGED / EV_FS_RENAMED)
    C_TIMER

C_FS watches path (optionally the whole subtree) and emits EV_FS_CHANGED and EV_FS_RENAMED. C_WATCHFS filters the event’s filename against the patterns (a list of POSIX regular expressions, compiled with regcomp) and, on a match, runs command.

Configuration

AttributeDefaultPurpose
path—Directory to watch
recursivefalseWatch the whole directory tree
patterns—List of POSIX regex. Only matching filenames trigger command
command—Shell command to run on a matching event
use_parameterfalseAppend the path of the changed file, quoted, as an argument to command
ignore_changed_eventfalseIgnore EV_FS_CHANGED
ignore_renamed_eventfalseIgnore EV_FS_RENAMED
infofalseLog discovered subdirectories

The command runs with /bin/sh -c, through run_process2(): no signal of the yuno blocked, no fd of the yuno inherited. With use_parameter the command and the quoted path of the file must fit in 16 KB (the path in PATH_MAX): one that does not fit is not run, and an ERROR says so (“Command with the file too long: not run”). Up to 7.29.3 it was cut at 4 KB with nothing said, and the cut command ran. For example, with:

{
    "path": "/yuneta/development/docs",
    "patterns": ".*\\.md",
    "command": "make html",
    "use_parameter": true
}

a change of a .md file runs make html '<path>/<file>'. The changes of a burst run the command once, 200-500 ms after the last one, with the last file that matched. Up to 7.29.3 the command was given no file: it got '/'.

Commands

CommandDescription
helpCommand help

Debugging

GClassLevelShows
C_WATCHFStrace_userWatch/match/exec activity

Enable with ycommand command-yuno id=<id> service=__yuno__ command=set-gclass-trace gclass=C_WATCHFS set=1 level=trace_user.