maintenance: disable cron on macOS
In eba1ba9
(maintenance: `git maintenance run` learned
`--scheduler=<scheduler>`, 2021-09-04), we introduced the ability to
specify a scheduler explicitly. This led to some extra checks around
whether an alternative scheduler was available. This added the
functionality of removing background maintenance from schedulers other
than the one selected.
On macOS, cron is technically available, but running 'crontab' triggers
a UI prompt asking for special permissions. This is the major reason why
launchctl is used as the default scheduler. The is_crontab_available()
method triggers this UI prompt, causing user disruption.
Remove this disruption by using an #ifdef to prevent running crontab
this way on macOS. This has the unfortunate downside that if a user
manually selects cron via the '--scheduler' option, then adjusting the
scheduler later will not remove the schedule from cron. The
'--scheduler' option ignores the is_available checks, which is how we
can get into this situation.
Extract the new check_crontab_process() method to avoid making the
'child' variable unused on macOS. The method is marked MAYBE_UNUSED
because it has no callers on macOS.
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
670e597399
commit
689a2aa719
27
builtin/gc.c
27
builtin/gc.c
@ -1961,15 +1961,11 @@ static int schtasks_update_schedule(int run_maintenance, int fd)
|
|||||||
return schtasks_remove_tasks();
|
return schtasks_remove_tasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_crontab_available(void)
|
MAYBE_UNUSED
|
||||||
|
static int check_crontab_process(const char *cmd)
|
||||||
{
|
{
|
||||||
const char *cmd = "crontab";
|
|
||||||
int is_available;
|
|
||||||
struct child_process child = CHILD_PROCESS_INIT;
|
struct child_process child = CHILD_PROCESS_INIT;
|
||||||
|
|
||||||
if (get_schedule_cmd(&cmd, &is_available))
|
|
||||||
return is_available;
|
|
||||||
|
|
||||||
strvec_split(&child.args, cmd);
|
strvec_split(&child.args, cmd);
|
||||||
strvec_push(&child.args, "-l");
|
strvec_push(&child.args, "-l");
|
||||||
child.no_stdin = 1;
|
child.no_stdin = 1;
|
||||||
@ -1984,6 +1980,25 @@ static int is_crontab_available(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_crontab_available(void)
|
||||||
|
{
|
||||||
|
const char *cmd = "crontab";
|
||||||
|
int is_available;
|
||||||
|
|
||||||
|
if (get_schedule_cmd(&cmd, &is_available))
|
||||||
|
return is_available;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
/*
|
||||||
|
* macOS has cron, but it requires special permissions and will
|
||||||
|
* create a UI alert when attempting to run this command.
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return check_crontab_process(cmd);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#define BEGIN_LINE "# BEGIN GIT MAINTENANCE SCHEDULE"
|
#define BEGIN_LINE "# BEGIN GIT MAINTENANCE SCHEDULE"
|
||||||
#define END_LINE "# END GIT MAINTENANCE SCHEDULE"
|
#define END_LINE "# END GIT MAINTENANCE SCHEDULE"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user