Commit 796fa0dd9ad3e31a526618681489bac184da8ae0

Edward Thomson 2022-01-16T20:19:07

sysdir: allow resetting cached system dirs

diff --git a/src/sysdir.c b/src/sysdir.c
index 84d212e..c0e14f5 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -189,9 +189,25 @@ int git_sysdir_global_init(void)
 	for (i = 0; !error && i < ARRAY_SIZE(git_sysdir__dirs); i++)
 		error = git_sysdir__dirs[i].guess(&git_sysdir__dirs[i].buf);
 
+	if (error)
+	    return error;
+
 	return git_runtime_shutdown_register(git_sysdir_global_shutdown);
 }
 
+int git_sysdir_reset(void)
+{
+    size_t i;
+    int error = 0;
+
+    for (i = 0; !error && i < ARRAY_SIZE(git_sysdir__dirs); ++i) {
+	git_str_dispose(&git_sysdir__dirs[i].buf);
+	error = git_sysdir__dirs[i].guess(&git_sysdir__dirs[i].buf);
+    }
+
+    return error;
+}
+
 static int git_sysdir_check_selector(git_sysdir_t which)
 {
 	if (which < ARRAY_SIZE(git_sysdir__dirs))
diff --git a/src/sysdir.h b/src/sysdir.h
index 43392a0..568f279 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -105,4 +105,9 @@ extern int git_sysdir_get(const git_str **out, git_sysdir_t which);
  */
 extern int git_sysdir_set(git_sysdir_t which, const char *paths);
 
+/**
+ * Reset search paths for global/system/xdg files.
+ */
+extern int git_sysdir_reset(void);
+
 #endif