diff mbox series

[20/23] fsm-listen-darwin: shutdown daemon if worktree root is moved/renamed

Message ID 496b3da35d0f9b8c68c6bc6c2bf2ca93ffe224b9.1644940774.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Builtin FSMonitor Part 3 | expand

Commit Message

Jeff Hostetler Feb. 15, 2022, 3:59 p.m. UTC
From: Jeff Hostetler <jeffhost@microsoft.com>

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>
---
 compat/fsmonitor/fsm-listen-darwin.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Derrick Stolee Feb. 24, 2022, 4:10 p.m. UTC | #1
On 2/15/2022 10:59 AM, Jeff Hostetler via GitGitGadget wrote:

> +		if (ef_is_root_changed(event_flags[k])) {
> +			/*
> +			 * The spelling of the pathname of the root directory
> +			 * has changed.  This includes the name of the root
> +			 * directory itself of of any parent directory in the

s/of of/or of/

> +			 * path.
> +			 *
> +			 * (There may be other conditions that throw this,
> +			 * but I couldn't find any information on it.)
> +			 *
> +			 * Force a shutdown now and avoid things getting
> +			 * out of sync.  The Unix domain socket is inside
> +			 * the .git directory and a spelling change will make
> +			 * it hard for clients to rendezvous with us.
> +			 */
> +			trace_printf_key(&trace_fsmonitor,
> +					 "event: root changed");
> +			goto force_shutdown;
> +		}
> +

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 87a8476b09f..d3afbbc53d6 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -178,6 +178,11 @@  static void log_flags_set(const char *path, const FSEventStreamEventFlags flag)
 	strbuf_release(&msg);
 }
 
+static int ef_is_root_changed(const FSEventStreamEventFlags ef)
+{
+	return (ef & kFSEventStreamEventFlagRootChanged);
+}
+
 static int ef_is_root_delete(const FSEventStreamEventFlags ef)
 {
 	return (ef & kFSEventStreamEventFlagItemIsDir &&
@@ -287,6 +292,26 @@  static void fsevent_callback(ConstFSEventStreamRef streamRef,
 			continue;
 		}
 
+		if (ef_is_root_changed(event_flags[k])) {
+			/*
+			 * The spelling of the pathname of the root directory
+			 * has changed.  This includes the name of the root
+			 * directory itself of of any parent directory in the
+			 * path.
+			 *
+			 * (There may be other conditions that throw this,
+			 * but I couldn't find any information on it.)
+			 *
+			 * Force a shutdown now and avoid things getting
+			 * out of sync.  The Unix domain socket is inside
+			 * the .git directory and a spelling change will make
+			 * it hard for clients to rendezvous with us.
+			 */
+			trace_printf_key(&trace_fsmonitor,
+					 "event: root changed");
+			goto force_shutdown;
+		}
+
 		if (ef_ignore_xattr(event_flags[k])) {
 			trace_printf_key(&trace_fsmonitor,
 					 "ignore-xattr: '%s', flags=0x%x",