scalar unregister: stop FSMonitor daemon

Especially on Windows, we will need to stop that daemon, just in case that the directory needs to be removed (the daemon would otherwise hold a handle to that directory, preventing it from being deleted). Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 18, 2022 at 21:40 UTC ec4c23116b2d1bb34b3952c0597032ca8ed6e5fc
1 file changed +13
contrib/scalar/scalar.c
+13
@@ -244,6 +244,16 @@ static int start_fsmonitor_daemon(void)
244 return 0;
245 }
246
247 +static int stop_fsmonitor_daemon(void)
248 +{
249 + assert(have_fsmonitor_support());
250 +
251 + if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING)
252 + return run_git("fsmonitor--daemon", "stop", NULL);
253 +
254 + return 0;
255 +}
256 +
257 static int register_dir(void)
258 {
259 if (add_or_remove_enlistment(1))
@@ -468,6 +478,9 @@ static int delete_enlistment(struct strbuf *enlistment)
478 strbuf_release(&parent);
479 #endif
480
481 + if (have_fsmonitor_support() && stop_fsmonitor_daemon())
482 + return error(_("failed to stop the FSMonitor daemon"));
483 +
484 if (remove_dir_recursively(enlistment, 0))
485 return error(_("failed to delete enlistment directory"));
486