summaryrefslogtreecommitdiff
path: root/src/checkout.c
diff options
context:
space:
mode:
authorBen Straub <bstraub@github.com>2012-07-26 19:09:37 -0700
committerBen Straub <bstraub@github.com>2012-07-26 19:09:37 -0700
commit6eb240b0b4d5938301efc14eafb440fa931366b6 (patch)
treeb9087eebbc9298a3b7f6e0556c443be56dc3ea55 /src/checkout.c
parent095ccc013f04398369d4063ff802d4c2928e367d (diff)
downloadlibgit2-6eb240b0b4d5938301efc14eafb440fa931366b6.tar.gz
Checkout: use caller's flags for open()
Diffstat (limited to 'src/checkout.c')
-rw-r--r--src/checkout.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 32cb3c809..052054701 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -64,8 +64,14 @@ static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf,
const git_oid *id, tree_walk_data *data)
{
int retcode = GIT_ERROR;
+ int fd = -1;
git_buf contents = GIT_BUF_INIT;
+ /* Deal with pre-existing files */
+ if (git_path_exists(git_buf_cstr(fnbuf)) &&
+ data->opts->existing_file_action == GIT_CHECKOUT_SKIP_EXISTING)
+ return 0;
+
/* Allow disabling of filters */
if (data->opts->disable_filters) {
git_blob *blob;
@@ -78,23 +84,17 @@ static int blob_contents_to_file(git_repository *repo, git_buf *fnbuf,
}
if (retcode < 0) goto bctf_cleanup;
- /* Deal with pre-existing files */
- if (git_path_exists(git_buf_cstr(fnbuf)) &&
- data->opts->existing_file_action == GIT_CHECKOUT_SKIP_EXISTING)
+ if ((retcode = git_futils_mkpath2file(git_buf_cstr(fnbuf), data->opts->dir_mode)) < 0)
goto bctf_cleanup;
- /* TODO: use p_open with flags */
- int fd = git_futils_creat_withpath(git_buf_cstr(fnbuf),
- data->opts->dir_mode,
- data->opts->file_mode);
- if (fd >= 0) {
- if (!p_write(fd, git_buf_cstr(&contents),
- git_buf_len(&contents)))
- retcode = 0;
- else
- retcode = GIT_ERROR;
- p_close(fd);
- }
+ fd = p_open(git_buf_cstr(fnbuf), data->opts->file_open_flags, data->opts->file_mode);
+ if (fd < 0) goto bctf_cleanup;
+
+ if (!p_write(fd, git_buf_cstr(&contents), git_buf_len(&contents)))
+ retcode = 0;
+ else
+ retcode = GIT_ERROR;
+ p_close(fd);
bctf_cleanup:
git_buf_free(&contents);