From 1a1b7a3afdd3edac9e8e351ce7e21c91404f8307 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sun, 31 Jul 2022 02:41:32 -0700 Subject: [PATCH] Linux: Add IN_MASK_CREATE and corresponding error handling in inotify_add_watch From https://man7.org/linux/man-pages/man7/inotify.7.html > **IN_MASK_CREATE** (since Linux 4.18) > > Watch pathname only if it does not already have a watch associated with it; the error EEXIST results if pathname is already being watched. --- lib/std/os.zig | 2 ++ lib/std/os/linux.zig | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/std/os.zig b/lib/std/os.zig index 5683c5300a..1192c72629 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4244,6 +4244,7 @@ pub const INotifyAddWatchError = error{ SystemResources, UserResourceLimitReached, NotDir, + WatchAlreadyExists, } || UnexpectedError; /// add a watch to an initialized inotify instance @@ -4266,6 +4267,7 @@ pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) I .NOMEM => return error.SystemResources, .NOSPC => return error.UserResourceLimitReached, .NOTDIR => return error.NotDir, + .EXIST => return error.WatchAlreadyExists, else => |err| return unexpectedErrno(err), } } diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index aa127db8ed..ae9b441b60 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -2976,6 +2976,7 @@ pub const IN = struct { pub const ONLYDIR = 0x01000000; pub const DONT_FOLLOW = 0x02000000; pub const EXCL_UNLINK = 0x04000000; + pub const MASK_CREATE = 0x10000000; pub const MASK_ADD = 0x20000000; pub const ISDIR = 0x40000000;