Skip to content

Commit de7e0b5

Browse files
jeffhostetlergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6504cfd commit de7e0b5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

compat/fsmonitor/fsm-listen-darwin.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ static void log_flags_set(const char *path, const FSEventStreamEventFlags flag)
106106
strbuf_release(&msg);
107107
}
108108

109+
static int ef_is_root_changed(const FSEventStreamEventFlags ef)
110+
{
111+
return (ef & kFSEventStreamEventFlagRootChanged);
112+
}
113+
109114
static int ef_is_root_delete(const FSEventStreamEventFlags ef)
110115
{
111116
return (ef & kFSEventStreamEventFlagItemIsDir &&
@@ -215,6 +220,26 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef,
215220
continue;
216221
}
217222

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+
218243
if (ef_ignore_xattr(event_flags[k])) {
219244
trace_printf_key(&trace_fsmonitor,
220245
"ignore-xattr: '%s', flags=0x%x",

0 commit comments

Comments
 (0)