sysdir: allow resetting cached system dirs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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