summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-03-23 11:48:41 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2017-03-23 12:12:39 +0000
commit5135ddaac6710cc0b4373764835dc6c519812bc4 (patch)
tree9ab19b4700db0c752701fdc2b256f2dbb6719285
parent301dc26a5a426870dc8f0728670c1c59ca42d300 (diff)
downloadlibgit2-5135ddaac6710cc0b4373764835dc6c519812bc4.tar.gz
Introduce `git_sysdir_expand_global_file`
Provide a mechanism for callers to expand the full path of a file in the global configuration directory (that is to say, the home directory) even if the file doesn't necessarily exist. This lets callers use their own logic for building paths separate from handling file existence.
-rw-r--r--src/sysdir.c11
-rw-r--r--src/sysdir.h12
2 files changed, 23 insertions, 0 deletions
diff --git a/src/sysdir.c b/src/sysdir.c
index ed11221a3..9312a7edb 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -275,3 +275,14 @@ int git_sysdir_find_template_dir(git_buf *path)
path, NULL, GIT_SYSDIR_TEMPLATE, "template");
}
+int git_sysdir_expand_global_file(git_buf *path, const char *filename)
+{
+ int error;
+
+ if ((error = git_sysdir_find_global_file(path, NULL)) == 0) {
+ if (filename)
+ error = git_buf_joinpath(path, path->ptr, filename);
+ }
+
+ return error;
+}
diff --git a/src/sysdir.h b/src/sysdir.h
index 11878981c..79f23818a 100644
--- a/src/sysdir.h
+++ b/src/sysdir.h
@@ -55,6 +55,18 @@ extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
*/
extern int git_sysdir_find_template_dir(git_buf *path);
+/**
+ * Expand the name of a "global" file (i.e. one in a user's home
+ * directory). Unlike `find_global_file` (above), this makes no
+ * attempt to check for the existence of the file, and is useful if
+ * you want the full path regardless of existence.
+ *
+ * @param path buffer to write the full path into
+ * @param filename name of file in the home directory
+ * @return 0 on success or -1 on error
+ */
+extern int git_sysdir_expand_global_file(git_buf *path, const char *filename);
+
typedef enum {
GIT_SYSDIR_SYSTEM = 0,
GIT_SYSDIR_GLOBAL = 1,