Skip to content

Commit ed1b7c3

Browse files
jeffhostetlergitster
authored andcommitted
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 <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ac29c6f commit ed1b7c3

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
@@ -100,7 +100,7 @@ static void log_flags_set(const char *path, const FSEventStreamEventFlags flag)
100100
if (flag & kFSEventStreamEventFlagItemCloned)
101101
strbuf_addstr(&msg, "ItemCloned|");
102102

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

106106
strbuf_release(&msg);
@@ -125,6 +125,31 @@ static int ef_is_dropped(const FSEventStreamEventFlags ef)
125125
ef & kFSEventStreamEventFlagUserDropped);
126126
}
127127

128+
/*
129+
* If an `xattr` change is the only reason we received this event,
130+
* then silently ignore it. Git doesn't care about xattr's. We
131+
* have to be careful here because the kernel can combine multiple
132+
* events for a single path. And because events always have certain
133+
* bits set, such as `ItemIsFile` or `ItemIsDir`.
134+
*
135+
* Return 1 if we should ignore it.
136+
*/
137+
static int ef_ignore_xattr(const FSEventStreamEventFlags ef)
138+
{
139+
static const FSEventStreamEventFlags mask =
140+
kFSEventStreamEventFlagItemChangeOwner |
141+
kFSEventStreamEventFlagItemCreated |
142+
kFSEventStreamEventFlagItemFinderInfoMod |
143+
kFSEventStreamEventFlagItemInodeMetaMod |
144+
kFSEventStreamEventFlagItemModified |
145+
kFSEventStreamEventFlagItemRemoved |
146+
kFSEventStreamEventFlagItemRenamed |
147+
kFSEventStreamEventFlagItemXattrMod |
148+
kFSEventStreamEventFlagItemCloned;
149+
150+
return ((ef & mask) == kFSEventStreamEventFlagItemXattrMod);
151+
}
152+
128153
static void fsevent_callback(ConstFSEventStreamRef streamRef,
129154
void *ctx,
130155
size_t num_of_events,
@@ -190,6 +215,13 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef,
190215
continue;
191216
}
192217

218+
if (ef_ignore_xattr(event_flags[k])) {
219+
trace_printf_key(&trace_fsmonitor,
220+
"ignore-xattr: '%s', flags=0x%x",
221+
path_k, event_flags[k]);
222+
continue;
223+
}
224+
193225
switch (fsmonitor_classify_path_absolute(state, path_k)) {
194226

195227
case IS_INSIDE_DOT_GIT_WITH_COOKIE_PREFIX:

0 commit comments

Comments
 (0)