diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2012-11-17 13:39:24 -0800 |
|---|---|---|
| committer | nulltoken <emeric.fermas@gmail.com> | 2012-11-17 18:30:34 -0800 |
| commit | 270160b91a0e55486f2cb6a6238c39fcd1271809 (patch) | |
| tree | 9ba94cc336c12c29955324b1d3572869154aab94 /src/config.c | |
| parent | d36451c9d4ba071de07106371553bf93f2717fc4 (diff) | |
| download | libgit2-270160b91a0e55486f2cb6a6238c39fcd1271809.tar.gz | |
config: Opening a nonexistent file returns ENOTFOUND
Diffstat (limited to 'src/config.c')
| -rw-r--r-- | src/config.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c index 01a54ecf2..412965b73 100644 --- a/src/config.c +++ b/src/config.c @@ -90,6 +90,13 @@ int git_config_add_file_ondisk( git_config_file *file = NULL; int res; + assert(cfg && path); + + if (!git_path_isfile(path)) { + giterr_set(GITERR_CONFIG, "File '%s' doesn't exists.", path); + return GIT_ENOTFOUND; + } + if (git_config_file__ondisk(&file, path) < 0) return -1; @@ -105,17 +112,22 @@ int git_config_add_file_ondisk( return 0; } -int git_config_open_ondisk(git_config **cfg, const char *path) +int git_config_open_ondisk(git_config **out, const char *path) { - if (git_config_new(cfg) < 0) - return -1; + int error; + git_config *config; - if (git_config_add_file_ondisk(*cfg, path, GIT_CONFIG_LEVEL_LOCAL, 0) < 0) { - git_config_free(*cfg); + *out = NULL; + + if (git_config_new(&config) < 0) return -1; - } - return 0; + if ((error = git_config_add_file_ondisk(config, path, GIT_CONFIG_LEVEL_LOCAL, 0)) < 0) + git_config_free(config); + else + *out = config; + + return error; } static int find_internal_file_by_level( |
