#`dmon` module to monitor changes in directories

1 messages · Page 1 of 1 (latest)

lean garden
#

https://github.com/ttytm/dmon-zig

I use it on a small server to hande interactions of some network devices.

Simple example:

const std = @import("std");
const dmon = @import("dmon");
const print = std.debug.print;

const Context = struct {
    triggerCount: u32 = 0,
};

pub fn watchCb(
    comptime Ctx: type,
    _: dmon.WatchId,
    action: dmon.Action,
    _: [*:0]const u8,
    file_path: [*:0]const u8,
    old_file_path: ?[*:0]const u8,
    context: *Ctx,
) void {
    print("Action: {}\n", .{action});
    print("File path: {s}\n", .{file_path});
    print("Old file path: {s}\n", .{old_file_path orelse ""});
    context.triggerCount += 1;
}

pub fn main() !void {
    dmon.init();
    defer dmon.deinit();

    const watch_path = "/home/user/Documents";
    const id = dmon.watch(Context, watch_path, watchCb, .{ .recursive = true }, &ctx);
    print("Starting to watch: {s}; Watcher ID: {d}\n", .{ watch_path, id });

    while (true) {
        if (ctx.triggerCount >= 3) break;
    }
}
vocal jetty
#

zig fetch --save https://github.com/ttytm/dmon-zig/archive/main.tar.gz

this is not enough. dmon.h is missing

#

maybe if you would add it to zon file as dependency, then it could download it? Honestly I am not very well versed in the package manager

#

other than this, it works very well! If you fix that, I will be super happy user of your lib ^_^

night python
lean garden
# vocal jetty ```zig fetch --save https://github.com/ttytm/dmon-zig/archive/main.tar.gz``` th...

I see, thanks for the info.

dmon.h is in src/bindings. and src is listed in the zon.
Ref regarding including paths .zon:

[..] A directory listed here means that all files within, recursively, are included.
It looks like the package manager is not good when using a submodule.

I went with a submodule since dmon is in a single header situation.
So afaik wouldn't be possible to add it as a "regular-fetched" dep from it's source and add the single include line C file workaround.
While there are real use cases to plainly copy third party code to a projects repo, they are very little. Imho it's bad practice in most cases.
So a submodule stays my first choice for a case like this one here, where a regular dep isn't feasible due to the single header status.

lean garden
lean garden
#

Looks like zig fetch is simply incompatible with submodules.

For an url target like "https://github.com/ttytm/dmon-zig/archive/main.tar.gz" it's logical that it isn't working because those "release" archives are stripped of things like the .git dir and don't include submodules.

But it's the same for a zig fetch git+https://github.com/ttytm/dmon-zig#master.
Having done a quick look into the fetch commands code, it looks like this is performing a shallow fetch.

So for now, deps have to be added as a dependency in build.zig.zon.
And if they are not compatible with that the thirdpary code will have to be directly added to the repo.

Anyway, the issue is fixed at the latest commit.