Merge branch 'cb/open-noatime-clear-errno'
authorJunio C Hamano <gitster@pobox.com>
Tue, 25 Aug 2015 21:57:10 +0000 (14:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Aug 2015 21:57:10 +0000 (14:57 -0700)
When trying to see that an object does not exist, a state errno
leaked from our "first try to open a packfile with O_NOATIME and
then if it fails retry without it" logic on a system that refuses
O_NOATIME. This confused us and caused us to die, saying that the
packfile is unreadable, when we should have just reported that the
object does not exist in that packfile to the caller.

* cb/open-noatime-clear-errno:
git_open_noatime: return with errno=0 on success

sha1_file.c
index ea78ba7cf062c92fe78e67ff4c0f5a0607e6aebd..08302f5857b8ad298809adf04a6bffc136f843a4 100644 (file)
@@ -1494,7 +1494,10 @@ int git_open_noatime(const char *name)
        static int sha1_file_open_flag = O_NOATIME;
 
        for (;;) {
-               int fd = open(name, O_RDONLY | sha1_file_open_flag);
+               int fd;
+
+               errno = 0;
+               fd = open(name, O_RDONLY | sha1_file_open_flag);
                if (fd >= 0)
                        return fd;