diff options
| author | Russell Belfer <rb@github.com> | 2012-05-25 09:44:56 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-05-25 09:44:56 -0700 |
| commit | 29ef309e2ca39f68d11c755710446ff6d396d203 (patch) | |
| tree | e026edd7b00baea86a34dddc769b894e4c155557 /src/fileops.c | |
| parent | 4728b55ac66cde7f8c104f0a8cc350d96a530f33 (diff) | |
| download | libgit2-29ef309e2ca39f68d11c755710446ff6d396d203.tar.gz | |
Make errors for system and global files consistent
The error codes from failed lookups of system and global files
on Windows were not consistent with the codes returned on other
platforms. This makes the error detection patterns match and
adds a unit test for the various errors.
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/fileops.c b/src/fileops.c index cd4b3c42a..95a65893c 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -417,11 +417,17 @@ int git_futils_find_system_file(git_buf *path, const char *filename) struct win32_path root; if (win32_expand_path(&root, L"%PROGRAMFILES%\\Git\\etc\\") < 0 || - win32_find_file(path, &root, filename) < 0) { - giterr_set(GITERR_OS, "Cannot find the system's Program Files directory"); + root.path[0] == L'%') /* i.e. no expansion happened */ + { + giterr_set(GITERR_OS, "Cannot locate the system's Program Files directory"); return -1; } + if (win32_find_file(path, &root, filename) < 0) { + git_buf_clear(path); + return GIT_ENOTFOUND; + } + return 0; #else @@ -442,11 +448,17 @@ int git_futils_find_global_file(git_buf *path, const char *filename) struct win32_path root; if (win32_expand_path(&root, L"%USERPROFILE%\\") < 0 || - win32_find_file(path, &root, filename) < 0) { - giterr_set(GITERR_OS, "Failed to lookup the current user's Windows profile"); + root.path[0] == L'%') /* i.e. no expansion happened */ + { + giterr_set(GITERR_OS, "Cannot locate the user's profile directory"); return -1; } + if (win32_find_file(path, &root, filename) < 0) { + git_buf_clear(path); + return GIT_ENOTFOUND; + } + return 0; #else const char *home = getenv("HOME"); |
