diff options
| author | Vicent Martà <tanoku@gmail.com> | 2012-02-15 16:54:17 +0100 |
|---|---|---|
| committer | Vicent Martà <tanoku@gmail.com> | 2012-03-03 02:28:50 +0100 |
| commit | 45d387ac78bcf3167d69b736d0b322717bc492d4 (patch) | |
| tree | 85f5568c2007a1e94106c9df1bef42ab60ab7aa2 /src/path.c | |
| parent | 60bc2d20c40e37e92e4e15479ac4dccbde069bec (diff) | |
| download | libgit2-45d387ac78bcf3167d69b736d0b322717bc492d4.tar.gz | |
refs: Error handling rework. WIP
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/path.c b/src/path.c index d2c292bf2..c882fe387 100644 --- a/src/path.c +++ b/src/path.c @@ -486,20 +486,23 @@ GIT_INLINE(int) is_dot_or_dotdot(const char *name) int git_path_direach( git_buf *path, - int (*fn)(void *, git_buf *), - void *arg) + int (*fn)(void *, git_buf *, git_error **), + void *arg, + git_error **error) { ssize_t wd_len; DIR *dir; struct dirent de_buf, *de; - if (git_path_to_dir(path) < GIT_SUCCESS) - return git_buf_lasterror(path); + if (git_path_to_dir(path, error) < 0) + return -1; wd_len = path->size; dir = opendir(path->ptr); - if (!dir) - return git__throw(GIT_EOSERR, "Failed to process `%s` tree structure. An error occured while opening the directory", path->ptr); + if (!dir) { + giterr_set(error, GITERR_OS, "Failed to `opendir` %s: %s", path->ptr, strerror(errno)); + return -1; + } while (p_readdir_r(dir, &de_buf, &de) == 0 && de != NULL) { int result; @@ -507,16 +510,18 @@ int git_path_direach( if (is_dot_or_dotdot(de->d_name)) continue; - if (git_buf_puts(path, de->d_name) < GIT_SUCCESS) - return git_buf_lasterror(path); + if (git_buf_puts(path, de->d_name) < 0) { + giterr_set_oom(error); + return -1; + } - result = fn(arg, path); + result = fn(arg, path, error); git_buf_truncate(path, wd_len); /* restore path */ - if (result != GIT_SUCCESS) { + if (result < 0) { closedir(dir); - return result; /* The callee is reponsible for setting the correct error message */ + return -1; } } |
