From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Johannes Sixt <j6t@kdbg.org>, git@vger.kernel.org
Subject: Re: [PATCH v2] Add an option not to use link(src, dest) && unlink(src) when that is unreliable
Date: Sat, 25 Apr 2009 09:49:11 -0700 [thread overview]
Message-ID: <7vbpqkznjs.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.DEB.1.00.0904251155130.10279@pacific.mpi-cbg.de> (Johannes Schindelin's message of "Sat, 25 Apr 2009 11:57:14 +0200 (CEST)")
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> It seems that accessing NTFS partitions with ufsd (at least on my EeePC)
> has an unnerving bug: if you link() a file and unlink() it right away,
> the target of the link() will have the correct size, but consist of NULs.
>
> It seems as if the calls are simply not serialized correctly, as single-stepping
> through the function move_temp_to_file() works flawlessly.
>
> As ufsd is "Commertial software" (sic!), I cannot fix it, and have to work
> around it in Git.
>
> At the same time, it seems that this fixes msysGit issues 222 and 229 to
> assume that Windows cannot handle link() && unlink().
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Acked-by: Johannes Sixt <j6t@kdbg.org>
Hannes, are you ok with this?
> diff --git a/environment.c b/environment.c
> index 4696885..10578d2 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -43,6 +43,10 @@ unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
> enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
> enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
> enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
> +#ifndef UNRELIABLE_HARDLINKS
> +#define UNRELIABLE_HARDLINKS 0
> +#endif
> +int unreliable_hardlinks = UNRELIABLE_HARDLINKS;
Hmm, this ifndef/define/endif is somewhat yucky to see especially in a .c
source file. Sorry, I do not think of a better alternative, though.
int unreliable_hardlinks = defined(UNRELIABLE_HARDLINKS)
would not work either X-<.
> diff --git a/sha1_file.c b/sha1_file.c
> index 8fe135d..bb6eecf 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -2225,7 +2225,9 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
> {
> int ret = 0;
>
> - if (link(tmpfile, filename))
> + if (unreliable_hardlinks)
> + ret = ~EEXIST; /* anything but EEXIST */
It is a bit too far away from the:
if (ret && ret != EEXIST)
you are trying to trigger with this hack, and without seeing that "if" in
the context anybody would go "Huh?". It is a good sign that this is
fragile (the later "if" may be rewritten by somebody else without
realizing this hack exists). Besides, it is (rather, "happens to be at
this moment") "anything non-zero but EEXIST".
I have a feeling that it would be much less fragile to write it like this,
as a label warns anybody touching the code to check where else the control
flow may come from.
diff --git a/sha1_file.c b/sha1_file.c
index 8fe135d..11969fc 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2225,7 +2225,9 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
{
int ret = 0;
- if (link(tmpfile, filename))
+ if (unreliable_hardlinks)
+ goto try_rename;
+ else if (link(tmpfile, filename))
ret = errno;
/*
@@ -2240,6 +2242,7 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
* left to unlink.
*/
if (ret && ret != EEXIST) {
+ try_rename:
if (!rename(tmpfile, filename))
goto out;
ret = errno;
next prev parent reply other threads:[~2009-04-25 16:55 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-23 10:53 [PATCH] Add an option not to use link(src, dest) && unlink(src) when that is unreliable Johannes Schindelin
2009-04-23 19:16 ` Johannes Sixt
2009-04-23 19:33 ` Johannes Schindelin
2009-04-25 9:57 ` [PATCH v2] " Johannes Schindelin
2009-04-25 16:49 ` Junio C Hamano [this message]
2009-04-25 17:40 ` Linus Torvalds
2009-04-25 18:38 ` Michael Gaber
2009-04-25 18:43 ` Linus Torvalds
2009-04-27 3:37 ` Jay Soffian
2009-04-25 18:50 ` Johannes Sixt
2009-04-25 17:05 ` Junio C Hamano
2009-04-26 17:39 ` Johannes Schindelin
2009-04-25 17:39 ` Linus Torvalds
2009-04-23 19:39 ` [PATCH] " Alex Riesen
2009-04-23 21:59 ` Johannes Schindelin
2009-04-24 5:44 ` Alex Riesen
2009-04-25 17:56 ` Linus Torvalds
2009-04-25 18:52 ` Johannes Sixt
2009-04-26 1:17 ` Junio C Hamano
2009-04-26 17:40 ` Johannes Schindelin
2009-04-27 12:00 ` [PATCH v3] " Johannes Schindelin
2009-04-27 15:15 ` Linus Torvalds
2009-04-27 16:11 ` Johannes Schindelin
2009-04-27 16:53 ` Linus Torvalds
2009-04-27 19:55 ` Junio C Hamano
2009-04-27 20:13 ` Linus Torvalds
2009-04-27 20:18 ` Linus Torvalds
2009-04-27 22:10 ` Junio C Hamano
2009-04-27 22:28 ` Johannes Schindelin
2009-04-27 23:06 ` Linus Torvalds
2009-04-27 22:32 ` [PATCH] Rename core.unreliableHardlinks to core.createObject Johannes Schindelin
2009-04-27 23:48 ` Junio C Hamano
2009-04-28 8:23 ` Johannes Schindelin
2009-04-28 8:44 ` Junio C Hamano
2009-04-28 14:50 ` Johannes Schindelin
2009-04-28 20:59 ` Junio C Hamano
2009-04-28 22:07 ` Johannes Schindelin
2009-04-26 17:38 ` [PATCH] Add an option not to use link(src, dest) && unlink(src) when that is unreliable Johannes Schindelin
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=7vbpqkznjs.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
/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).