Skip to contentSkip to conversation

Cross-directory hard links

PATCH In review Cedric Staniewski 3 participants 6 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

PATCH 1/1 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.

---

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(-)
Makefile +4 -0
index 6e21643..b00e22d 100644
@@ -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 \
Signature · 1 line
1.6.3.49.g4d15.dirty
#2 lore raw

Re: [PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

Quoted 2 lines · Johannes Schindelin

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

#3 lore raw

Re: [PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

Hi,

Quoted 8 lines · Cedric Staniewski
Quoted 2 lines · Johannes Schindelin

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

#4 lore raw

Re: [PATCH] Add NO_CROSS_DIRECTORY_HARDLINKS support to the Makefile

Quoted 1 line · Johannes Schindelin

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.

#5 lore raw
In reply to Cedric Staniewski
Quoted 4 lines · Cedric Staniewski

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.

Signature · 3 lines
f.anthony.n.finch  <[email protected]>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.