git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 5/5] DON'T APPLY YET: maintenance: remove cleanup code

From
Max Gautier <mg@max.gautier.name>
Date
Mar 18, 2024, 15:31 UTC
Message-ID
<20240318153257.27451-6-mg@max.gautier.name>
In-Reply-To
<20240318153257.27451-1-mg@max.gautier.name>

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@max.gautier.name>
---
 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
Previous: Max Gautier
Message 22 of 22 in “maintenance: use packaged systemd units”
  1. 0/5 maintenance: use packaged systemd unitsMax Gautier, Mar 18, 2024
  2. 1/5 maintenance: package systemd unitsMax Gautier, Mar 18, 2024
  3. Patrick SteinhardtMar 21, 2024
  4. Max GautierMar 21, 2024
  5. Patrick SteinhardtMar 21, 2024
  6. Max GautierMar 21, 2024
  7. Patrick SteinhardtMar 21, 2024
  8. Max GautierMar 21, 2024
  9. Max GautierMar 21, 2024
  10. 2/5 maintenance: add fixed random delay to systemd timersMax Gautier, Mar 18, 2024
  11. Patrick SteinhardtMar 21, 2024
  12. Max GautierMar 21, 2024
  13. 4/5 maintenance: update systemd scheduler docsMax Gautier, Mar 18, 2024
  14. Patrick SteinhardtMar 21, 2024
  15. 3/5 maintenance: use packaged systemd unitsMax Gautier, Mar 18, 2024
  16. Max GautierMar 19, 2024
  17. Eric SunshineMar 19, 2024
  18. Junio C HamanoMar 19, 2024
  19. Max GautierMar 19, 2024
  20. Patrick SteinhardtMar 21, 2024
  21. Max GautierMar 21, 2024
  22. 5/5 DON'T APPLY YET: maintenance: remove cleanup codeMax Gautier, Mar 18, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.