Skip to content

Commit

Permalink
scalar unregister: stop FSMonitor daemon
Browse files Browse the repository at this point in the history
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).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and derrickstolee committed Aug 31, 2022
1 parent 5805305 commit 8c5472f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions contrib/scalar/scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ static int start_fsmonitor_daemon(void)
return 0;
}

static int stop_fsmonitor_daemon(void)
{
#ifdef HAVE_FSMONITOR_DAEMON_BACKEND
struct strbuf err = STRBUF_INIT;
struct child_process cp = CHILD_PROCESS_INIT;

cp.git_cmd = 1;
strvec_pushl(&cp.args, "fsmonitor--daemon", "stop", NULL);
if (!pipe_command(&cp, NULL, 0, NULL, 0, &err, 0)) {
strbuf_release(&err);
return 0;
}

if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING) {
write_in_full(2, err.buf, err.len);
strbuf_release(&err);
return error(_("could not stop the FSMonitor daemon"));
}

strbuf_release(&err);
#endif

return 0;
}

static int register_dir(void)
{
int res = add_or_remove_enlistment(1);
Expand All @@ -295,6 +320,9 @@ static int unregister_dir(void)
if (add_or_remove_enlistment(0) < 0)
res = -1;

if (stop_fsmonitor_daemon() < 0)
res = -1;

return res;
}

Expand Down

0 comments on commit 8c5472f

Please sign in to comment.