Commit d0cd6c42 by nulltoken

path: Make direach() return EUSER on callback error

parent 38859f29
...@@ -869,6 +869,7 @@ typedef struct { ...@@ -869,6 +869,7 @@ typedef struct {
uint32_t flags; uint32_t flags;
uint32_t mkdir_flags; uint32_t mkdir_flags;
mode_t dirmode; mode_t dirmode;
int error;
} cp_r_info; } cp_r_info;
#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10) #define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10)
...@@ -907,20 +908,23 @@ static int _cp_r_callback(void *ref, git_buf *from) ...@@ -907,20 +908,23 @@ static int _cp_r_callback(void *ref, git_buf *from)
return 0; return 0;
if (git_buf_joinpath( if (git_buf_joinpath(
&info->to, info->to_root, from->ptr + info->from_prefix) < 0) &info->to, info->to_root, from->ptr + info->from_prefix) < 0) {
return -1; error = -1;
goto exit;
}
if (p_lstat(info->to.ptr, &to_st) < 0) { if (p_lstat(info->to.ptr, &to_st) < 0) {
if (errno != ENOENT && errno != ENOTDIR) { if (errno != ENOENT && errno != ENOTDIR) {
giterr_set(GITERR_OS, giterr_set(GITERR_OS,
"Could not access %s while copying files", info->to.ptr); "Could not access %s while copying files", info->to.ptr);
return -1; error = -1;
goto exit;
} }
} else } else
exists = true; exists = true;
if ((error = git_path_lstat(from->ptr, &from_st)) < 0) if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
return error; goto exit;
if (S_ISDIR(from_st.st_mode)) { if (S_ISDIR(from_st.st_mode)) {
mode_t oldmode = info->dirmode; mode_t oldmode = info->dirmode;
...@@ -934,13 +938,14 @@ static int _cp_r_callback(void *ref, git_buf *from) ...@@ -934,13 +938,14 @@ static int _cp_r_callback(void *ref, git_buf *from)
error = _cp_r_mkdir(info, from); error = _cp_r_mkdir(info, from);
/* recurse onto target directory */ /* recurse onto target directory */
if (!error && (!exists || S_ISDIR(to_st.st_mode))) if (!error && (!exists || S_ISDIR(to_st.st_mode)) &&
error = git_path_direach(from, _cp_r_callback, info); ((error = git_path_direach(from, _cp_r_callback, info)) == GIT_EUSER))
error = info->error;
if (oldmode != 0) if (oldmode != 0)
info->dirmode = oldmode; info->dirmode = oldmode;
return error; goto exit;
} }
if (exists) { if (exists) {
...@@ -950,7 +955,8 @@ static int _cp_r_callback(void *ref, git_buf *from) ...@@ -950,7 +955,8 @@ static int _cp_r_callback(void *ref, git_buf *from)
if (p_unlink(info->to.ptr) < 0) { if (p_unlink(info->to.ptr) < 0) {
giterr_set(GITERR_OS, "Cannot overwrite existing file '%s'", giterr_set(GITERR_OS, "Cannot overwrite existing file '%s'",
info->to.ptr); info->to.ptr);
return -1; error = -1;
goto exit;
} }
} }
...@@ -963,7 +969,7 @@ static int _cp_r_callback(void *ref, git_buf *from) ...@@ -963,7 +969,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
/* Make container directory on demand if needed */ /* Make container directory on demand if needed */
if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 && if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 &&
(error = _cp_r_mkdir(info, from)) < 0) (error = _cp_r_mkdir(info, from)) < 0)
return error; goto exit;
/* make symlink or regular file */ /* make symlink or regular file */
if (S_ISLNK(from_st.st_mode)) if (S_ISLNK(from_st.st_mode))
...@@ -977,6 +983,8 @@ static int _cp_r_callback(void *ref, git_buf *from) ...@@ -977,6 +983,8 @@ static int _cp_r_callback(void *ref, git_buf *from)
error = git_futils_cp(from->ptr, info->to.ptr, usemode); error = git_futils_cp(from->ptr, info->to.ptr, usemode);
} }
exit:
info->error = error;
return error; return error;
} }
...@@ -997,6 +1005,7 @@ int git_futils_cp_r( ...@@ -997,6 +1005,7 @@ int git_futils_cp_r(
info.flags = flags; info.flags = flags;
info.dirmode = dirmode; info.dirmode = dirmode;
info.from_prefix = path.size; info.from_prefix = path.size;
info.error = 0;
git_buf_init(&info.to, 0); git_buf_init(&info.to, 0);
/* precalculate mkdir flags */ /* precalculate mkdir flags */
...@@ -1018,6 +1027,9 @@ int git_futils_cp_r( ...@@ -1018,6 +1027,9 @@ int git_futils_cp_r(
git_buf_free(&path); git_buf_free(&path);
git_buf_free(&info.to); git_buf_free(&info.to);
if (error == GIT_EUSER)
error = info.error;
return error; return error;
} }
......
...@@ -336,7 +336,7 @@ static int pack_backend__refresh(git_odb_backend *_backend) ...@@ -336,7 +336,7 @@ static int pack_backend__refresh(git_odb_backend *_backend)
git_buf_free(&path); git_buf_free(&path);
if (error < 0) if (error < 0)
return error; return -1;
git_vector_sort(&backend->packs); git_vector_sort(&backend->packs);
return 0; return 0;
......
...@@ -765,10 +765,10 @@ int git_path_direach( ...@@ -765,10 +765,10 @@ int git_path_direach(
git_buf_truncate(path, wd_len); /* restore path */ git_buf_truncate(path, wd_len); /* restore path */
if (result < 0) { if (result) {
closedir(dir); closedir(dir);
git__free(de_buf); git__free(de_buf);
return -1; return GIT_EUSER;
} }
} }
......
...@@ -299,7 +299,7 @@ static int packed_loadloose(refdb_fs_backend *backend) ...@@ -299,7 +299,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
git_buf_free(&refs_path); git_buf_free(&refs_path);
return error; return (error == GIT_EUSER) ? -1 : error;
} }
static int refdb_fs_backend__exists( static int refdb_fs_backend__exists(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment