aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-05 14:27:00 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-05 14:27:00 -0700
commite43d3e995f8ca14a1ea887a5628ca0930ecfdf9d (patch)
tree2eca27aba4bd25ebb716658dcd5028212f2ec5f6 /src
parentc20df72d7319ff55ed4e5c9c7ff1abaab951d0bd (diff)
downloadbun-e43d3e995f8ca14a1ea887a5628ca0930ecfdf9d.tar.gz
bun-e43d3e995f8ca14a1ea887a5628ca0930ecfdf9d.tar.zst
bun-e43d3e995f8ca14a1ea887a5628ca0930ecfdf9d.zip
package.json
Former-commit-id: 2299f44cc9092dad2ef48ea54af2555c192a723e
Diffstat (limited to 'src')
-rw-r--r--src/watcher.zig73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/watcher.zig b/src/watcher.zig
index 5b4a8431a..9948a01da 100644
--- a/src/watcher.zig
+++ b/src/watcher.zig
@@ -258,43 +258,48 @@ pub fn NewWatcher(comptime ContextType: type) type {
parent_hash: HashType,
comptime copy_file_path: bool,
) !void {
- // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
- var event = std.mem.zeroes(KEvent);
+ const index = this.eventlist_used;
+ const watchlist_id = this.watchlist.len;
- event.flags = os.EV_ADD | os.EV_CLEAR | os.EV_ENABLE;
- // we want to know about the vnode
- event.filter = std.os.EVFILT_VNODE;
+ if (isMac) {
- // monitor:
- // - Write
- // - Rename
+ // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
+ var event = std.mem.zeroes(KEvent);
- // we should monitor:
- // - Delete
- event.fflags = std.os.NOTE_WRITE | std.os.NOTE_RENAME | std.os.NOTE_DELETE;
+ event.flags = os.EV_ADD | os.EV_CLEAR | os.EV_ENABLE;
+ // we want to know about the vnode
+ event.filter = std.os.EVFILT_VNODE;
- // id
- event.ident = @intCast(usize, fd);
+ // monitor:
+ // - Write
+ // - Rename
- const index = this.eventlist_used;
- this.eventlist_used += 1;
- const watchlist_id = this.watchlist.len;
- // Store the hash for fast filtering later
- event.udata = @intCast(usize, watchlist_id);
- this.eventlist[index] = event;
+ // we should monitor:
+ // - Delete
+ event.fflags = std.os.NOTE_WRITE | std.os.NOTE_RENAME | std.os.NOTE_DELETE;
- // This took a lot of work to figure out the right permutation
- // Basically:
- // - We register the event here.
- // our while(true) loop above receives notification of changes to any of the events created here.
- _ = std.os.system.kevent(
- try this.getQueue(),
- this.eventlist[index .. index + 1].ptr,
- 1,
- this.eventlist[index .. index + 1].ptr,
- 0,
- null,
- );
+ // id
+ event.ident = @intCast(usize, fd);
+
+ this.eventlist_used += 1;
+
+ // Store the hash for fast filtering later
+ event.udata = @intCast(usize, watchlist_id);
+ this.eventlist[index] = event;
+
+ // This took a lot of work to figure out the right permutation
+ // Basically:
+ // - We register the event here.
+ // our while(true) loop above receives notification of changes to any of the events created here.
+ _ = std.os.system.kevent(
+ try this.getQueue(),
+ this.eventlist[index .. index + 1].ptr,
+ 1,
+ this.eventlist[index .. index + 1].ptr,
+ 0,
+ null,
+ );
+ }
this.watchlist.appendAssumeCapacity(.{
.file_path = if (copy_file_path) try this.allocator.dupe(u8, file_path) else file_path,
@@ -323,6 +328,8 @@ pub fn NewWatcher(comptime ContextType: type) type {
};
const parent_hash = Watcher.getHash(Fs.PathName.init(file_path).dirWithTrailingSlash());
+ const index = this.eventlist_used;
+ const watchlist_id = this.watchlist.len;
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
var event = std.mem.zeroes(KEvent);
@@ -334,17 +341,13 @@ pub fn NewWatcher(comptime ContextType: type) type {
// monitor:
// - Write
// - Rename
-
- // we should monitor:
// - Delete
event.fflags = std.os.NOTE_WRITE | std.os.NOTE_RENAME | std.os.NOTE_DELETE;
// id
event.ident = @intCast(usize, fd);
- const index = this.eventlist_used;
this.eventlist_used += 1;
- const watchlist_id = this.watchlist.len;
// Store the hash for fast filtering later
event.udata = @intCast(usize, watchlist_id);
this.eventlist[index] = event;