From 8a4d77f990b4453e42e3c2cc61df5175b39586d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 15 May 2015 12:15:45 +0200 Subject: [PATCH 1/3] path: don't let direach overwrite the callback's error message This function deals with functions doing IO which means the amount of errors that can happen is quit large. It does not help if it always ovewrites the underlying error message with a less understandable version of "something went wrong". Instead, only use this generic message if there was no error set by the callback. --- src/path.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/path.c b/src/path.c index df6762c3a..81b4d51df 100644 --- a/src/path.c +++ b/src/path.c @@ -1060,11 +1060,13 @@ int git_path_direach( if ((error = git_buf_put(path, de_path, de_len)) < 0) break; + giterr_clear(); error = fn(arg, path); git_buf_truncate(path, wd_len); /* restore path */ - if (error != 0) { + /* Only set our own error if the callback did not set one already */ + if (error != 0 && !giterr_last()) { giterr_set_after_callback(error); break; } From 54738368ec469dd9706c5c8f97d24affde9edae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 15 May 2015 12:18:05 +0200 Subject: [PATCH 2/3] fileops: set an error message if we fail to link a file Now that `git_path_direach` lets us specify an error message to report, set an appropriate error message while linking. --- src/fileops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index 0587c446f..566aed1c1 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -861,7 +861,8 @@ static int _cp_r_callback(void *ref, git_buf *from) /* make symlink or regular file */ if (info->flags & GIT_CPDIR_LINK_FILES) { - error = p_link(from->ptr, info->to.ptr); + if ((error = p_link(from->ptr, info->to.ptr)) < 0) + giterr_set(GITERR_OS, "failed to link '%s'", from->ptr); } else if (S_ISLNK(from_st.st_mode)) { error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size); } else { From edef91ee25eddcda1db9af64c99d3913c45e3a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 15 May 2015 12:23:27 +0200 Subject: [PATCH 3/3] fileops: set an error on write error for file copy We set an error if we get an error when reading, but we don't bother setting an error message for write failing. This causes a cryptic error to be shown to the user when the target filesystem is full. --- src/fileops.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fileops.c b/src/fileops.c index 566aed1c1..b7b55159f 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -703,6 +703,9 @@ static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done) error = (int)len; } + if (error < 0) + giterr_set(GITERR_OS, "write error while copying file"); + if (close_fd_when_done) { p_close(ifd); p_close(ofd);