{"thread":{"id":"7726","subject":"[PATCH] Fix overwriting of the files to apply the patch to in git-apply","startedAt":"2007-04-18T16:29:59Z","lastAt":"2007-04-18T16:33:21Z","messageCount":2,"participants":["Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"39789","messageId":"81b0412b0704180929h7960bedeje87050fa5ca543b0@mail.gmail.com","threadId":"7726","inReplyTo":null,"subject":"[PATCH] Fix overwriting of the files to apply the patch to in git-apply","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-04-18T16:29:59Z","receivedAt":"2007-04-18T16:29:59Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"The check for existence of a file was wrong: it assumed it was a directory\nand reset the errno (twice: directly and by calling lstat). So if an entry\nexisted and was _not_ a directory no attempt was made to rename into it,\nbecause the errno (expected by renaming code) was already reset to 0.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nThe decision to check for directory first looks suboptimal.\nWhy not try to _rename_ first and if that fails check if we've got a directory?\nAn existing file seems to be more of a common case.\n\nP.S. gmail: will resend unless applied\n\n builtin-apply.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\n\nFrom 23d8d5677f8c34c8c17bef1c7678cca08ba856b6 Mon Sep 17 00:00:00 2001\nFrom: Alex Riesen <raa.lkml@gmail.com>\nDate: Wed, 18 Apr 2007 18:24:53 +0200\nSubject: [PATCH] Fix overwriting of the files to apply the patch to in git-apply\n\nThe check for existence of a file was wrong: it assumed it was a directory\nand reset the errno (twice: directly and by calling lstat). So if an entry\nexisted and was _not_ a directory no attempt was made to rename into it,\nbecause the errno (expected by renaming code) was already reset to 0.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n builtin-apply.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex fd92ef7..240cc08 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2417,7 +2417,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned\n \t\t */\n \t\tstruct stat st;\n \t\terrno = 0;\n-\t\tif (!lstat(path, &st) && S_ISDIR(st.st_mode) && !rmdir(path))\n+\t\tif (!lstat(path, &st) && (!S_ISDIR(st.st_mode) || !rmdir(path)))\n \t\t\terrno = EEXIST;\n \t}\n \n-- \n1.5.1.1.195.gdcb3f\n\n"},{"id":"39791","messageId":"81b0412b0704180933t7f161bcah57bce6dbea43a710@mail.gmail.com","threadId":"7726","inReplyTo":"81b0412b0704180929h7960bedeje87050fa5ca543b0@mail.gmail.com","subject":"Re: [PATCH] Fix overwriting of the files to apply the patch to in git-apply","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-04-18T16:33:21Z","receivedAt":"2007-04-18T16:33:21Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 4/18/07, Alex Riesen <raa.lkml@gmail.com> wrote:\n> The decision to check for directory first looks suboptimal.\n> Why not try to _rename_ first and if that fails check if we've got a directory?\n> An existing file seems to be more of a common case.\n\nSimplier to code and read, for one.\n"}]}