Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-04-25 08:31:32 +0300
committerJunio C Hamano <gitster@pobox.com>2023-04-25 08:31:32 +0300
commit9ce9dea4e1c2419cca126d29fa7730baa078a11b (patch)
tree6bec2aeb2df40cfe1435c476c9e48da58cebd875 /apply.c
parent7580f92ffa970b9484ac214f7b53cec5e26ca4bc (diff)
parent0d1bd1dfb37ef25e1911777c94129fc769ffec38 (diff)
Sync with Git 2.40.1
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/apply.c b/apply.c
index 9b7288bc92..e2d55eadfa 100644
--- a/apply.c
+++ b/apply.c
@@ -4586,7 +4586,7 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
FILE *rej;
char namebuf[PATH_MAX];
struct fragment *frag;
- int cnt = 0;
+ int fd, cnt = 0;
struct strbuf sb = STRBUF_INIT;
for (cnt = 0, frag = patch->fragments; frag; frag = frag->next) {
@@ -4626,7 +4626,17 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
memcpy(namebuf, patch->new_name, cnt);
memcpy(namebuf + cnt, ".rej", 5);
- rej = fopen(namebuf, "w");
+ fd = open(namebuf, O_CREAT | O_EXCL | O_WRONLY, 0666);
+ if (fd < 0) {
+ if (errno != EEXIST)
+ return error_errno(_("cannot open %s"), namebuf);
+ if (unlink(namebuf))
+ return error_errno(_("cannot unlink '%s'"), namebuf);
+ fd = open(namebuf, O_CREAT | O_EXCL | O_WRONLY, 0666);
+ if (fd < 0)
+ return error_errno(_("cannot open %s"), namebuf);
+ }
+ rej = fdopen(fd, "w");
if (!rej)
return error_errno(_("cannot open %s"), namebuf);