[PATCH] Fix overwriting of the files to apply the patch to in git-apply

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The check for existence of a file was wrong: it assumed it was a directory
and reset the errno (twice: directly and by calling lstat). So if an entry
existed and was _not_ a directory no attempt was made to rename into it,
because the errno (expected by renaming code) was already reset to 0.

Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx>
---

The decision to check for directory first looks suboptimal.
Why not try to _rename_ first and if that fails check if we've got a directory?
An existing file seems to be more of a common case.

P.S. gmail: will resend unless applied

builtin-apply.c |    2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
From 23d8d5677f8c34c8c17bef1c7678cca08ba856b6 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@xxxxxxxxx>
Date: Wed, 18 Apr 2007 18:24:53 +0200
Subject: [PATCH] Fix overwriting of the files to apply the patch to in git-apply

The check for existence of a file was wrong: it assumed it was a directory
and reset the errno (twice: directly and by calling lstat). So if an entry
existed and was _not_ a directory no attempt was made to rename into it,
because the errno (expected by renaming code) was already reset to 0.

Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx>
---
 builtin-apply.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index fd92ef7..240cc08 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2417,7 +2417,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned
 		 */
 		struct stat st;
 		errno = 0;
-		if (!lstat(path, &st) && S_ISDIR(st.st_mode) && !rmdir(path))
+		if (!lstat(path, &st) && (!S_ISDIR(st.st_mode) || !rmdir(path)))
 			errno = EEXIST;
 	}
 
-- 
1.5.1.1.195.gdcb3f


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]