Skip to content

Commit 1671c78

Browse files
jeffhostetlerdscho
authored andcommitted
compat/fsmonitor/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]>
1 parent bd8ab71 commit 1671c78

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
@@ -178,6 +178,11 @@ static void log_flags_set(const char *path, const FSEventStreamEventFlags flag)
178178
strbuf_release(&msg);
179179
}
180180

181+
static int ef_is_root_changed(const FSEventStreamEventFlags ef)
182+
{
183+
return (ef & kFSEventStreamEventFlagRootChanged);
184+
}
185+
181186
static int ef_is_root_delete(const FSEventStreamEventFlags ef)
182187
{
183188
return (ef & kFSEventStreamEventFlagItemIsDir &&
@@ -287,6 +292,26 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef,
287292
continue;
288293
}
289294

295+
if (ef_is_root_changed(event_flags[k])) {
296+
/*
297+
* The spelling of the pathname of the root directory
298+
* has changed. This includes the name of the root
299+
* directory itself of of any parent directory in the
300+
* path.
301+
*
302+
* (There may be other conditions that throw this,
303+
* but I couldn't find any information on it.)
304+
*
305+
* Force a shutdown now and avoid things getting
306+
* out of sync. The Unix domain socket is inside
307+
* the .git directory and a spelling change will make
308+
* it hard for clients to rendezvous with us.
309+
*/
310+
trace_printf_key(&trace_fsmonitor,
311+
"event: root changed");
312+
goto force_shutdown;
313+
}
314+
290315
if (ef_ignore_xattr(event_flags[k])) {
291316
trace_printf_key(&trace_fsmonitor,
292317
"ignore-xattr: '%s', flags=0x%x",

0 commit comments

Comments
 (0)