my.fswatch

Members

Aliases

FileChangeEvent
alias FileChangeEvent = SumType!(Event.Access, Event.Attribute, Event.CloseWrite, Event.CloseNoWrite, Event.Create, Event.Delete, Event.DeleteSelf, Event.Modify, Event.MoveSelf, Event.Rename, Event.Open, Event.Overflow)
Undocumented in source.

Enums

PollEvent
enum PollEvent

Type of event to poll for.

PollStatus
enum PollStatus

What each bit in PollResult.status represent.

Functions

fileWatch
auto fileWatch()

Construct a FileWatch.

Manifest constants

ContentEvents
enum ContentEvents;

Listens for create/modify/removal of files and directories.

MetadataEvents
enum MetadataEvents;

Listen for events that change the metadata.

Structs

Event
struct Event
Undocumented in source.
FdPoll
struct FdPoll

A file descriptor to poll.

FdPoller
struct FdPoller

Uses the linux poll syscall to wait for activity on the file descriptors.

FileWatch
struct FileWatch

An instance of a FileWatcher

Monitor
struct Monitor

Monitor root's for filesystem changes which create/remove/modify files/directories.

MonitorResult
struct MonitorResult
Undocumented in source.
PollResult
struct PollResult

File descriptors that triggered.

Meta

Authors

Joakim Brännström (joakim.brannstrom@gmx.com)

This is based on webfreak's fswatch. I had problems with the API as it where because I needed to be able to watch multiple directories, filter what files are to be watched and to be robust against broken symlinks.

Lets say you want to watch a directory for changes and add all directories to be watched too.

auto fw = fileWatch();
fw.watchRecurse("my_dir");
while (true) {
    auto ev = fw.wait;
    foreach (e; ev) {
        e.match!(
        (Event.Access x) => writeln(x),
        (Event.Attribute x) => writeln(x),
        (Event.CloseWrite x) => writeln(x),
        (Event.CloseNoWrite x) => writeln(x),
        (Event.Create x) { fw.watchRecurse(x.path); },
        (Event.Delete x) => writeln(x),
        (Event.DeleteSelf x) => writeln(x),
        (Event.Modify x) => writeln(x),
        (Event.MoveSelf x) => writeln(x),
        (Event.Rename x) => writeln(x),
        (Event.Open x) => writeln(x),
        );
    }
}