* Write the schedule information into a git-maintenance@ .timer * file using a custom minute. This timer file cannot use the templating * system, so we generate a specific file for each. */
| 2999 | * system, so we generate a specific file for each. |
| 3000 | */ |
| 3001 | static int systemd_timer_write_timer_file(enum schedule_priority schedule, |
| 3002 | int minute) |
| 3003 | { |
| 3004 | int res = -1; |
| 3005 | char *filename; |
| 3006 | FILE *file; |
| 3007 | const char *unit; |
| 3008 | char *schedule_pattern = NULL; |
| 3009 | const char *frequency = get_frequency(schedule); |
| 3010 | char *local_timer_name = xstrfmt(SYSTEMD_UNIT_FORMAT, frequency, "timer"); |
| 3011 | |
| 3012 | filename = xdg_config_home_systemd(local_timer_name); |
| 3013 | |
| 3014 | if (safe_create_leading_directories(the_repository, filename)) { |
| 3015 | error(_("failed to create directories for '%s'"), filename); |
| 3016 | goto error; |
| 3017 | } |
| 3018 | file = fopen_or_warn(filename, "w"); |
| 3019 | if (!file) |
| 3020 | goto error; |
| 3021 | |
| 3022 | switch (schedule) { |
| 3023 | case SCHEDULE_HOURLY: |
| 3024 | schedule_pattern = xstrfmt("*-*-* 1..23:%02d:00", minute); |
| 3025 | break; |
| 3026 | |
| 3027 | case SCHEDULE_DAILY: |
| 3028 | schedule_pattern = xstrfmt("Tue..Sun *-*-* 0:%02d:00", minute); |
| 3029 | break; |
| 3030 | |
| 3031 | case SCHEDULE_WEEKLY: |
| 3032 | schedule_pattern = xstrfmt("Mon 0:%02d:00", minute); |
| 3033 | break; |
| 3034 | |
| 3035 | default: |
| 3036 | BUG("Unhandled schedule_priority"); |
| 3037 | } |
| 3038 | |
| 3039 | unit = "# This file was created and is maintained by Git.\n" |
| 3040 | "# Any edits made in this file might be replaced in the future\n" |
| 3041 | "# by a Git command.\n" |
| 3042 | "\n" |
| 3043 | "[Unit]\n" |
| 3044 | "Description=Optimize Git repositories data\n" |
| 3045 | "\n" |
| 3046 | "[Timer]\n" |
| 3047 | "OnCalendar=%s\n" |
| 3048 | "Persistent=true\n" |
| 3049 | "\n" |
| 3050 | "[Install]\n" |
| 3051 | "WantedBy=timers.target\n"; |
| 3052 | if (fprintf(file, unit, schedule_pattern) < 0) { |
| 3053 | error(_("failed to write to '%s'"), filename); |
| 3054 | fclose(file); |
| 3055 | goto error; |
| 3056 | } |
| 3057 | if (fclose(file) == EOF) { |
| 3058 | error_errno(_("failed to flush '%s'"), filename); |
no test coverage detected