This removes code to remove old git-maintenance systemd timer and service user units which were written in $XDG_CONFIG_HOME by git previous versions. Signed-off-by: Max Gautier <mg@xxxxxxxxxxxxxxxx> --- builtin/gc.c | 54 +++------------------------------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 981db8e297..6ac184eaf5 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2303,12 +2303,7 @@ static int is_systemd_timer_available(void) return real_is_systemd_timer_available(); } -static char *xdg_config_home_systemd(const char *filename) -{ - return xdg_config_home_for("systemd/user", filename); -} - -static int systemd_set_units_state(int enable) +static int systemd_set_units_state(int run_maintenance, int fd UNUSED) { const char *cmd = "systemctl"; struct child_process child = CHILD_PROCESS_INIT; @@ -2317,7 +2312,7 @@ static int systemd_set_units_state(int enable) strvec_split(&child.args, cmd); strvec_pushl(&child.args, "--user", "--force", "--now", - enable ? "enable" : "disable", + run_maintenance ? "enable" : "disable", "git-maintenance@hourly.timer", "git-maintenance@daily.timer", "git-maintenance@weekly.timer", NULL); @@ -2334,49 +2329,6 @@ static int systemd_set_units_state(int enable) return 0; } -static void systemd_delete_user_unit(char const *unit) -{ - char const file_start_stale[] = "# This file was created and is" - " maintained by Git."; - char file_start_user[sizeof(file_start_stale)] = {'\0'}; - - char *filename = xdg_config_home_systemd(unit); - int handle = open(filename, O_RDONLY); - - /* - ** Check this is actually our file and we're not removing a legitimate - ** user override. - */ - if (handle == -1 && !is_missing_file_error(errno)) - warning(_("failed to delete '%s'"), filename); - else { - read(handle, file_start_user, sizeof(file_start_stale) - 1); - close(handle); - if (strcmp(file_start_stale, file_start_user) == 0) { - if (unlink(filename) == 0) - warning(_("deleted stale unit file '%s'"), filename); - else if (!is_missing_file_error(errno)) - warning(_("failed to delete '%s'"), filename); - } - } - - free(filename); -} - -static int systemd_timer_update_schedule(int run_maintenance, int fd UNUSED) -{ - /* - * A previous version of Git wrote the units in the user configuration - * directory. Clean these up, if they exist. - */ - systemd_delete_user_unit("git-maintenance@hourly.timer"); - systemd_delete_user_unit("git-maintenance@daily.timer"); - systemd_delete_user_unit("git-maintenance@weekly.timer"); - systemd_delete_user_unit("git-maintenance@.timer"); - systemd_delete_user_unit("git-maintenance@.service"); - return systemd_set_units_state(run_maintenance); -} - enum scheduler { SCHEDULER_INVALID = -1, SCHEDULER_AUTO, @@ -2399,7 +2351,7 @@ static const struct { [SCHEDULER_SYSTEMD] = { .name = "systemctl", .is_available = is_systemd_timer_available, - .update_schedule = systemd_timer_update_schedule, + .update_schedule = systemd_set_units_state, }, [SCHEDULER_LAUNCHCTL] = { .name = "launchctl", -- 2.44.0