diff --git a/CHANGELOG.md b/CHANGELOG.md index 949ea99d..d1f6833e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add experimental `filewatch/` module for listening to file system changes. - Add `bundle/who-is` to query which bundle a file on disk was installed by. - Add `geomean` function - Add `:R` and `:W` flags to `os/pipe` to create blocking pipes on Posix and Windows systems. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 8d60cc81..96110a5c 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -4387,10 +4387,11 @@ `Shorthand for adding scripts during an install. Scripts will be installed to (string (dyn *syspath*) "/bin") by default and will be set to be executable.` [manifest src &opt dest chmod-mode] - (default dest (string "bin" (sep) (->> src (string/split "/") last))) + (default dest (->> src (string/split "/") last)) + (def bin-dest (string "bin" (sep) dest)) (default chmod-mode 8r755) (os/mkdir (string (dyn *syspath*) (sep) "bin")) - (bundle/add-file manifest src dest chmod-mode)) + (bundle/add-file manifest src bin-dest chmod-mode)) (defn bundle/update-all "Reinstall all bundles" diff --git a/src/core/ev.c b/src/core/ev.c index 9a13b583..30f03671 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -988,6 +988,20 @@ int janet_channel_take(JanetChannel *channel, Janet *out) { return janet_channel_pop(channel, out, 2); } +JanetChannel *janet_channel_make(uint32_t limit) { + janet_assert(limit <= INT32_MAX, "bad limit"); + JanetChannel *channel = janet_abstract(&janet_channel_type, sizeof(JanetChannel)); + janet_chan_init(channel, (int32_t) limit, 0); + return channel; +} + +JanetChannel *janet_channel_make_threaded(uint32_t limit) { + janet_assert(limit <= INT32_MAX, "bad limit"); + JanetChannel *channel = janet_abstract_threaded(&janet_channel_type, sizeof(JanetChannel)); + janet_chan_init(channel, (int32_t) limit, 0); + return channel; +} + /* Channel Methods */ JANET_CORE_FN(cfun_channel_push, diff --git a/src/core/filewatch.c b/src/core/filewatch.c index d90394e4..05dd04e9 100644 --- a/src/core/filewatch.c +++ b/src/core/filewatch.c @@ -89,6 +89,9 @@ static void janet_watcher_init(JanetWatcher *watcher, JanetChannel *channel, uin do { fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); } while (fd == -1 && errno == EINTR); + if (fd == -1) { + janet_panicv(janet_ev_lasterr()); + } watcher->watch_descriptors = janet_table(0); watcher->channel = channel; watcher->default_flags = default_flags; @@ -101,6 +104,9 @@ static void janet_watcher_add(JanetWatcher *watcher, const char *path, uint32_t do { result = inotify_add_watch(watcher->stream->handle, path, flags); } while (result == -1 && errno == EINTR); + if (result == -1) { + janet_panicv(janet_ev_lasterr()); + } Janet name = janet_cstringv(path); Janet wd = janet_wrap_integer(result); janet_table_put(watcher->watch_descriptors, name, wd); @@ -117,7 +123,7 @@ static void janet_watcher_remove(JanetWatcher *watcher, const char *path) { result = inotify_rm_watch(watcher->stream->handle, watch_handle); } while (result != -1 && errno == EINTR); if (result == -1) { - janet_panicf("%s", janet_strerror(errno)); + janet_panicv(janet_ev_lasterr()); } } @@ -277,7 +283,7 @@ static const JanetAbstractType janet_filewatch_at = { JANET_CORE_FN(cfun_filewatch_make, "(filewatch/make channel &opt default-flags)", - "Create a new filewatcher.") { + "Create a new filewatcher that will give events to a channel channel.") { janet_arity(argc, 1, -1); JanetChannel *channel = janet_getchannel(argv, 0); JanetWatcher *watcher = janet_abstract(&janet_filewatch_at, sizeof(JanetWatcher)); diff --git a/src/include/janet.h b/src/include/janet.h index db31478c..cccb0ccd 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -1450,6 +1450,8 @@ JANET_API int32_t janet_abstract_incref(void *abst); JANET_API int32_t janet_abstract_decref(void *abst); /* Expose channel utilities */ +JanetChannel *janet_channel_make(uint32_t limit); +JanetChannel *janet_channel_make_threaded(uint32_t limit); JanetChannel *janet_getchannel(const Janet *argv, int32_t n); JanetChannel *janet_optchannel(const Janet *argv, int32_t argc, int32_t n, JanetChannel *dflt); JANET_API int janet_channel_give(JanetChannel *channel, Janet x);