fsm-listen-darwin: shutdown daemon if worktree root is moved/renamed

Teach the listener thread to shutdown the daemon if the spelling of the worktree root directory changes. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed May 26, 2022 at 21:47 UTC de7e0b58ea4bb1ca8242e677096dae50f96e9b7e
1 file changed +25
compat/fsmonitor/fsm-listen-darwin.c
+25
@@ -106,6 +106,11 @@ static void log_flags_set(const char *path, const FSEventStreamEventFlags flag)
106 strbuf_release(&msg);
107 }
108
109 +static int ef_is_root_changed(const FSEventStreamEventFlags ef)
110 +{
111 + return (ef & kFSEventStreamEventFlagRootChanged);
112 +}
113 +
114 static int ef_is_root_delete(const FSEventStreamEventFlags ef)
115 {
116 return (ef & kFSEventStreamEventFlagItemIsDir &&
@@ -215,6 +220,26 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef,
220 continue;
221 }
222
223 + if (ef_is_root_changed(event_flags[k])) {
224 + /*
225 + * The spelling of the pathname of the root directory
226 + * has changed. This includes the name of the root
227 + * directory itself or of any parent directory in the
228 + * path.
229 + *
230 + * (There may be other conditions that throw this,
231 + * but I couldn't find any information on it.)
232 + *
233 + * Force a shutdown now and avoid things getting
234 + * out of sync. The Unix domain socket is inside
235 + * the .git directory and a spelling change will make
236 + * it hard for clients to rendezvous with us.
237 + */
238 + trace_printf_key(&trace_fsmonitor,
239 + "event: root changed");
240 + goto force_shutdown;
241 + }
242 +
243 if (ef_ignore_xattr(event_flags[k])) {
244 trace_printf_key(&trace_fsmonitor,
245 "ignore-xattr: '%s', flags=0x%x",