threads / discuss / 19283

Cross-directory hard links

Subject: Cross-directory hard links

## tl;dr

6 messages between May 11, 2009 and May 11, 2009.

replies: 5people: 3as markdown or json

Cedric Staniewski· May 11, 2009, 10:41 UTC · lore
Hi everybody,

git commit 6a0861 [1] made bin/git the target of the builtins hard links which results in 'cross-directory' hard links. While the Makefile always works fine for the local installation via 'make install', these links can raise trouble when installing git via package manager.

The problem only occurs on systems where git's bin and lib directories will be installed on different file systems, e.g. if /usr and /usr/lib are different mount points. If you attempt to install a git package which was built with DESTDIR=/usr and contains such hard links, tar will fail to extract either bin/git or the builtins (depending on how tar resolves the hard links) complaining about a 'Invalid cross-device link'.

I know such a setup is probably quite rare, but the problem can easily be fixed by always copying bin/git to lib/git-add instead of hard linking it.

Cheers, Cedric

[1] http://git.kernel.org/?p=git/git.git;a=commit;h=6a0861a8a3295395238c8126c6e74c66b715c595

Johannes Schindelin· May 11, 2009, 11:02 UTC · re: Cedric Staniewski · lore

[PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

When the installed programs are tar'ed up and installed on a system where bin/ and libexec/git-core/ live on different file systems, we do not want libexec/git-core/git-* to be hardlinks to bin/git.

Noticed by Cedric Staniewski.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Mon, 11 May 2009, Cedric Staniewski wrote:
	> git commit 6a0861 [1] made bin/git the target of the builtins 
	> hard links which results in 'cross-directory' hard links. While the 
	> Makefile always works fine for the local installation via 'make 
	> install', these links can raise trouble when installing git via
	> package manager.
	I do not understand how this commit could be responsible, but here 
	is an attempt to fix things.
 Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
index 6e21643..b00e22d 100644
--- a/Makefile
+++ b/Makefile
@@ -175,6 +175,9 @@ all::
 # Define OBJECT_CREATION_USES_RENAMES if your operating systems has problems
 # when hardlinking a file to another name and unlinking the original file right
 # away (some NTFS drivers seem to zero the contents in that scenario).
+#
+# Define NO_CROSS_DIRECTORY_HARDLINKS if you plan to distribute the installed
+# programs as a tar, where bin/ and libexec/ might be on different file systems.
 
 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1549,6 +1552,7 @@ endif
 	bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
 	execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
 	{ $(RM) "$$execdir/git-add$X" && \
+		test -z "$(NO_CROSS_DIRECTORY_HARDLINKS)" && \
 		ln "$$bindir/git$X" "$$execdir/git-add$X" 2>/dev/null || \
 		cp "$$bindir/git$X" "$$execdir/git-add$X"; } && \
 	{ for p in $(filter-out git-add$X,$(BUILT_INS)); do \
-- 
1.6.3.49.g4d15.dirty
Cedric Staniewski· May 11, 2009, 16:29 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

Johannes Schindelin wrote:
> 	I do not understand how this commit could be responsible, but here 
> 	is an attempt to fix things.

The important difference is that before this commit, git-add was hardlinked to a file outside of DESTDIR. Thus, when the build directory was removed or you tar'ed DESTDIR, git-add was just a regular file and all the other builtins were hardlinked to it.

Behavior before commit: $ touch git git-add && mkdir bin libexec && cp git bin && ln git-add libexec/ && ### the relevant line tar caf git.tar.gz bin libexec && tar tfv git.tar.gz

bin/ bin/git libexec/ libexec/git-add

Behavior after commit: $ touch git git-add && mkdir bin libexec && cp git bin && ln bin/git libexec/git-add && ### the relevant line tar caf git.tar.gz bin libexec && tar tfv git.tar.gz

bin/ bin/git libexec/ libexec/git-add link to bin/git

Johannes Schindelin· May 11, 2009, 19:08 UTC · re: Cedric Staniewski · lore

Re: [PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

Hi,
On Mon, 11 May 2009, Cedric Staniewski wrote:
Show 8 quoted lines
> Johannes Schindelin wrote:
> > 	I do not understand how this commit could be responsible, but here 
> > 	is an attempt to fix things.
> 
> The important difference is that before this commit, git-add was
> hardlinked to a file outside of DESTDIR. Thus, when the build directory
> was removed or you tar'ed DESTDIR, git-add was just a regular file and
> all the other builtins were hardlinked to it.
Ah.
But you did not say if you like/tested the patch or not.

Ciao, Dscho

Cedric Staniewski· May 11, 2009, 20:05 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

Johannes Schindelin wrote:
> But you did not say if you like/tested the patch or not.
Oh, sorry. Of course, it works as intended and I'm fine with applying it.
Thanks for your work.
Tony Finch· May 11, 2009, 16:40 UTC · re: Cedric Staniewski · lore

Re: Cross-directory hard links

On Mon, 11 May 2009, Cedric Staniewski wrote:
>
> The problem only occurs on systems where git's bin and lib directories will be
> installed on different file systems, e.g. if /usr and /usr/lib are different
> mount points.

Some filesystems (a.g. AFS) do not support cross-directory hardlinks even when they are under the same mount point.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.

← back to recent threads