git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Faye-Lund <kusmabite@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, msysGit <msysgit@googlegroups.com>
Subject: Re: [PATCH 2/2] A loose object is not corrupt if it cannot be read due to EMFILE
Date: Thu, 18 Nov 2010 15:19:03 +0100	[thread overview]
Message-ID: <AANLkTi=L1Z6kxubMf3yPUfpY9ugd+Qan+yCxi3dp4oR4@mail.gmail.com> (raw)
In-Reply-To: <1288299210-27092-2-git-send-email-gitster@pobox.com>

On Thu, Oct 28, 2010 at 10:53 PM, Junio C Hamano <gitster@pobox.com> wrote:
> "git fsck" bails out with a claim that a loose object that cannot be
> read but exists on the filesystem to be corrupt, which is wrong when
> read_object() failed due to e.g. EMFILE.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  sha1_file.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/sha1_file.c b/sha1_file.c
> index 5ed5497..f709ed6 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -2090,16 +2090,21 @@ void *read_sha1_file_repl(const unsigned char *sha1,
>                          const unsigned char **replacement)
>  {
>        const unsigned char *repl = lookup_replace_object(sha1);
> -       void *data = read_object(repl, type, size);
> +       void *data;
>        char *path;
>        const struct packed_git *p;
>
> +       errno = 0;
> +       data = read_object(repl, type, size);
>        if (data) {
>                if (replacement)
>                        *replacement = repl;
>                return data;
>        }
>
> +       if (errno != ENOENT)
> +               die_errno("failed to read object %s", sha1_to_hex(sha1));
> +
>        /* die if we replaced an object with one that does not exist */
>        if (repl != sha1)
>                die("replacement %s not found for %s",
> --
> 1.7.3.2.191.g2d0e57
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

This patch seems to break clone/fetch on Windows:

$ GIT_TRACE=1 git clone http://github.com/kusma/rocket.git clone-test
trace: built-in: git 'clone' 'http://github.com/kusma/rocket.git' 'clone-test'
Cloning into clone-test...
trace: run_command: 'git-remote-http' 'origin'
'http://github.com/kusma/rocket.git'
trace: run_command: 'fetch-pack' '--stateless-rpc' '--lock-pack'
'--thin' 'http://github.com/kusma/rocket.git/' 'refs/heads/master'
'refs/heads/work/icon' 'refs/heads/work/io-callback'
'refs/heads/work/sdl-example' 'refs/tags/v0.8'
trace: built-in: git 'fetch-pack' '--stateless-rpc' '--lock-pack'
'--thin' 'http://github.com/kusma/rocket.git/' 'refs/heads/master'
'refs/heads/work/icon' 'refs/heads/work/io-callback'
'refs/heads/work/sdl-example' 'refs/tags/v0.8'
fatal: failed to read object 7ea7cabd967429886c26e78b3ec573d54a95fa9d: No error
fatal: The remote end hung up unexpectedly

What happens, is that read_object returns NULL, but errno is 0.
Further, it looks to me like read_object can only return NULL through
the unpack_sha1_file (problem with the compressed data) or
read_packed_sha1 (find_pack_entry() failure) code-paths.

errno is set to ENOENT by open_sha1_file (through map_sha1_file)
before any possible error-points. I guess this makes the "errno = 0"
redundant, but I think it improves readability of the code. I'm
guessing that errno gets overwritten by some other call, losing the
ENOENT. Perhaps some unintended side-effect of one of the
compat/mingw.[ch]-wrappers?

I did find such a case, but fixing it doesn't do the trick for me:

---8<---
diff --git a/compat/mingw.c b/compat/mingw.c
index 29f4036..fdbf093 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -198,9 +198,10 @@ static inline time_t filetime_to_time_t(const FILETIME *ft)
  */
 static int do_lstat(int follow, const char *file_name, struct stat *buf)
 {
+	int err;
 	WIN32_FILE_ATTRIBUTE_DATA fdata;

-	if (!(errno = get_file_attr(file_name, &fdata))) {
+	if (!(err = get_file_attr(file_name, &fdata))) {
 		buf->st_ino = 0;
 		buf->st_gid = 0;
 		buf->st_uid = 0;
@@ -233,6 +234,7 @@ static int do_lstat(int follow, const char
*file_name, struct stat *buf)
 		}
 		return 0;
 	}
+	errno = err;
 	return -1;
 }

---8<---

The following patch makes clone complete again, but I doubt it's the
right solution. However, I'm out of ideas for now. Anyone? :)

diff --git a/sha1_file.c b/sha1_file.c
index 25f6965..9d4cb9c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2102,7 +2102,7 @@ void *read_sha1_file_repl(const unsigned char *sha1,
 		return data;
 	}

-	if (errno != ENOENT)
+	if (errno && errno != ENOENT)
 		die_errno("failed to read object %s", sha1_to_hex(sha1));

 	/* die if we replaced an object with one that does not exist */

  reply	other threads:[~2010-11-18 14:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-28 20:53 [PATCH 1/2] read_sha1_file(): report correct name of packfile with a corrupt object Junio C Hamano
2010-10-28 20:53 ` [PATCH 2/2] A loose object is not corrupt if it cannot be read due to EMFILE Junio C Hamano
2010-11-18 14:19   ` Erik Faye-Lund [this message]
2010-11-18 16:43     ` Johannes Sixt
2010-11-18 17:21       ` Erik Faye-Lund
2010-11-18 17:29         ` Jonathan Nieder
2010-11-18 18:18           ` Erik Faye-Lund
2010-11-18 18:23             ` Casey Dahlin
2010-11-18 20:27             ` Jonathan Nieder
2010-10-29  8:08 ` [PATCH 1/2] read_sha1_file(): report correct name of packfile with a corrupt object Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=L1Z6kxubMf3yPUfpY9ugd+Qan+yCxi3dp4oR4@mail.gmail.com' \
    --to=kusmabite@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=msysgit@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).