Skip to content

Commit a8ea9c3

Browse files
jeffhostetlerdscho
authored andcommitted
compat/fsmonitor/fsm-listen-darwin: ignore FSEvents caused by xattr changes on MacOS
Ignore FSEvents resulting from `xattr` changes. Git does not care about xattr's or changes to xattr's, so don't waste time collecting these events in the daemon nor transmitting them to clients. Various security tools add xattrs to files and/or directories, such as to mark them as having been downloaded. We should ignore these events since it doesn't affect the content of the file/directory or the normal meta-data that Git cares about. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 72ffbb7 commit a8ea9c3

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

compat/fsmonitor/fsm-listen-darwin.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static void log_flags_set(const char *path, const FSEventStreamEventFlags flag)
172172
if (flag & kFSEventStreamEventFlagItemCloned)
173173
strbuf_addstr(&msg, "ItemCloned|");
174174

175-
trace_printf_key(&trace_fsmonitor, "fsevent: '%s', flags=%u %s",
175+
trace_printf_key(&trace_fsmonitor, "fsevent: '%s', flags=0x%x %s",
176176
path, flag, msg.buf);
177177

178178
strbuf_release(&msg);
@@ -197,6 +197,31 @@ static int ef_is_dropped(const FSEventStreamEventFlags ef)
197197
ef & kFSEventStreamEventFlagUserDropped);
198198
}
199199

200+
/*
201+
* If an `xattr` change is the only reason we received this event,
202+
* then silently ignore it. Git doesn't care about xattr's. We
203+
* have to be careful here because the kernel can combine multiple
204+
* events for a single path. And because events always have certain
205+
* bits set, such as `ItemIsFile` or `ItemIsDir`.
206+
*
207+
* Return 1 if we should ignore it.
208+
*/
209+
static int ef_ignore_xattr(const FSEventStreamEventFlags ef)
210+
{
211+
static const FSEventStreamEventFlags mask =
212+
kFSEventStreamEventFlagItemChangeOwner |
213+
kFSEventStreamEventFlagItemCreated |
214+
kFSEventStreamEventFlagItemFinderInfoMod |
215+
kFSEventStreamEventFlagItemInodeMetaMod |
216+
kFSEventStreamEventFlagItemModified |
217+
kFSEventStreamEventFlagItemRemoved |
218+
kFSEventStreamEventFlagItemRenamed |
219+
kFSEventStreamEventFlagItemXattrMod |
220+
kFSEventStreamEventFlagItemCloned;
221+
222+
return ((ef & mask) == kFSEventStreamEventFlagItemXattrMod);
223+
}
224+
200225
static void fsevent_callback(ConstFSEventStreamRef streamRef,
201226
void *ctx,
202227
size_t num_of_events,
@@ -262,6 +287,13 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef,
262287
continue;
263288
}
264289

290+
if (ef_ignore_xattr(event_flags[k])) {
291+
trace_printf_key(&trace_fsmonitor,
292+
"ignore-xattr: '%s', flags=0x%x",
293+
path_k, event_flags[k]);
294+
continue;
295+
}
296+
265297
switch (fsmonitor_classify_path_absolute(state, path_k)) {
266298

267299
case IS_INSIDE_DOT_GIT_WITH_COOKIE_PREFIX:

0 commit comments

Comments
 (0)