diff options
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/src/fileops.c b/src/fileops.c index 0418e9e52..98dcd3269 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -404,7 +404,6 @@ typedef struct { size_t baselen; uint32_t flags; int depth; - git_error_state error; } futils__rmdir_data; #define FUTILS_MAX_DEPTH 100 @@ -474,16 +473,14 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path) data->depth++; error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data); - if (error == GIT_EUSER) - return error; data->depth--; if (error < 0) - goto done; + return error; if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0) - goto done; + return error; if ((error = p_rmdir(path->ptr)) < 0) { if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 && @@ -502,8 +499,7 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path) else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0) error = futils__error_cannot_rmdir(path->ptr, "still present"); -done: - return giterr_capture(&data->error, error); + return error; } static int futils__rmdir_empty_parent(void *opaque, git_buf *path) @@ -512,9 +508,9 @@ static int futils__rmdir_empty_parent(void *opaque, git_buf *path) int error = 0; if (git_buf_len(path) <= data->baselen) - return giterr_capture(&data->error, GIT_ITEROVER); + error = GIT_ITEROVER; - if (p_rmdir(git_buf_cstr(path)) < 0) { + else if (p_rmdir(git_buf_cstr(path)) < 0) { int en = errno; if (en == ENOENT || en == ENOTDIR) { @@ -526,7 +522,7 @@ static int futils__rmdir_empty_parent(void *opaque, git_buf *path) } } - return giterr_capture(&data->error, error); + return error; } int git_futils_rmdir_r( @@ -552,10 +548,10 @@ int git_futils_rmdir_r( error = git_path_walk_up( &fullpath, base, futils__rmdir_empty_parent, &data); - if (error == GIT_EUSER) - error = giterr_restore(&data.error); - if (error == GIT_ITEROVER) + if (error == GIT_ITEROVER) { + giterr_clear(); error = 0; + } git_buf_free(&fullpath); @@ -859,7 +855,6 @@ typedef struct { uint32_t flags; uint32_t mkdir_flags; mode_t dirmode; - git_error_state error; } cp_r_info; #define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10) @@ -899,19 +894,19 @@ static int _cp_r_callback(void *ref, git_buf *from) if ((error = git_buf_joinpath( &info->to, info->to_root, from->ptr + info->from_prefix)) < 0) - goto done; + return error; if (!(error = git_path_lstat(info->to.ptr, &to_st))) exists = true; else if (error != GIT_ENOTFOUND) - goto done; + return error; else { giterr_clear(); error = 0; } if ((error = git_path_lstat(from->ptr, &from_st)) < 0) - goto done; + return error; if (S_ISDIR(from_st.st_mode)) { mode_t oldmode = info->dirmode; @@ -925,16 +920,13 @@ static int _cp_r_callback(void *ref, git_buf *from) error = _cp_r_mkdir(info, from); /* 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, 0, _cp_r_callback, info); - if (error == GIT_EUSER) - return error; - } if (oldmode != 0) info->dirmode = oldmode; - goto done; + return error; } if (exists) { @@ -944,8 +936,7 @@ static int _cp_r_callback(void *ref, git_buf *from) if (p_unlink(info->to.ptr) < 0) { giterr_set(GITERR_OS, "Cannot overwrite existing file '%s'", info->to.ptr); - error = -1; - goto done; + return GIT_EEXISTS; } } @@ -958,7 +949,7 @@ static int _cp_r_callback(void *ref, git_buf *from) /* Make container directory on demand if needed */ if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 && (error = _cp_r_mkdir(info, from)) < 0) - goto done; + return error; /* make symlink or regular file */ if (S_ISLNK(from_st.st_mode)) @@ -972,8 +963,7 @@ static int _cp_r_callback(void *ref, git_buf *from) error = git_futils_cp(from->ptr, info->to.ptr, usemode); } -done: - return giterr_capture(&info->error, error); + return error; } int git_futils_cp_r( @@ -1015,9 +1005,6 @@ int git_futils_cp_r( git_buf_free(&path); git_buf_free(&info.to); - if (error == GIT_EUSER) - error = giterr_restore(&info.error); - return error; } |