git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/6] Makefile: use "ln -f" instead of "rm && ln"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 29, 2021, 16:31 UTC
Message-ID
<patch-5.7-f81708f6120-20210329T162327Z-avarab@gmail.com>
In-Reply-To
<cover-0.7-00000000000-20210329T162327Z-avarab@gmail.com>

Change the invocations and behavior of "ln-or-cp.sh" to not assume that we're going to "rm" the file in question beforehand.

This reduces the complexity of these rules, and as a bonus means it's now safe to "make install" on a system that may have running "git" programs, before this we'd be racing the "rm && ln/cp" and wouldn't have a working "git" (or one of the built-ins) in the interim.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Makefile    | 10 ++--------
 ln-or-cp.sh |  5 ++---
 2 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index 29d9bade5a8..466df1a8e90 100644
--- a/Makefile
+++ b/Makefile
@@ -2204,8 +2204,7 @@ version.sp version.s version.o: EXTRA_CPPFLAGS = \
 
 $(BUILT_INS): GIT-LNCPFLAGS
 $(BUILT_INS): git$X
-	$(QUIET_BUILT_IN)$(RM) $@ && \
-	./ln-or-cp.sh \
+	$(QUIET_BUILT_IN)./ln-or-cp.sh \
 		--install-symlinks "$(INSTALL_SYMLINKS)" \
 		$< $@
 
@@ -2558,8 +2557,7 @@ git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
 
 $(REMOTE_CURL_ALIASES): GIT-LNCPFLAGS
 $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
-	$(QUIET_LNCP)$(RM) $@ && \
-	./ln-or-cp.sh \
+	$(QUIET_LNCP)./ln-or-cp.sh \
 		--install-symlinks "$(INSTALL_SYMLINKS)" \
 		$< $@
 
@@ -3021,7 +3019,6 @@ endif
 	destdir_from_execdir_SQ=$$(echo '$(gitexecdir_relative_SQ)' | sed -e 's|[^/][^/]*|..|g') && \
 	{ test "$$bindir/" = "$$execdir/" || \
 	  for p in git$X $(filter $(install_bindir_programs),$(ALL_PROGRAMS)); do \
-		$(RM) "$$execdir/$$p" && \
 		./ln-or-cp.sh \
 			--install-symlinks "$(INSTALL_SYMLINKS)" \
 			--no-install-hardlinks "$(NO_INSTALL_HARDLINKS)" \
@@ -3031,7 +3028,6 @@ endif
 	  done; \
 	} && \
 	for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \
-		$(RM) "$$bindir/$$p" && \
 		./ln-or-cp.sh \
 			--install-symlinks "$(INSTALL_SYMLINKS)" \
 			--no-install-hardlinks "$(NO_INSTALL_HARDLINKS)" \
@@ -3039,7 +3035,6 @@ endif
 			"$$bindir/git$X" "$$bindir/$$p"; \
 	done && \
 	for p in $(BUILT_INS); do \
-		$(RM) "$$execdir/$$p" && \
 		if test -z "$(SKIP_DASHED_BUILT_INS)"; \
 		then \
 			./ln-or-cp.sh \
@@ -3051,7 +3046,6 @@ endif
 	done && \
 	remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
 	for p in $$remote_curl_aliases; do \
-		$(RM) "$$execdir/$$p" && \
 		./ln-or-cp.sh \
 			--install-symlinks "$(INSTALL_SYMLINKS)" \
 			--no-install-hardlinks "$(NO_INSTALL_HARDLINKS)" \
diff --git a/ln-or-cp.sh b/ln-or-cp.sh
index 663ffd0489d..37380993c64 100755
--- a/ln-or-cp.sh
+++ b/ln-or-cp.sh
@@ -40,11 +40,10 @@ link="$2"
 hardlink_or_cp () {
 	if test -z "$no_install_hardlinks" -a -z "$no_cross_directory_hardlinks"
 	then
-		if ! ln "$target" "$link"
+		if ! ln -f "$target" "$link"
 		then
 			cp "$target" "$link"
 		fi
-
 	else
 		cp "$target" "$link"
 	fi
@@ -53,7 +52,7 @@ hardlink_or_cp () {
 main_with_fallbacks () {
 	if test -n "$install_symlinks" -o -n "$no_install_hardlinks"
 	then
-		if ! ln -s "$symlink_target" "$link"
+		if ! ln -f -s "$symlink_target" "$link"
 		then
 			hardlink_or_cp
 		fi
-- 
2.31.1.461.gd47399f6574
Previous: Junio C HamanoNext: Junio C Hamano
Message 32 of 48 in “Makefile: generate 'git' as 'cc [...] -o git+ && mv git+ git'”
  1. Makefile: generate 'git' as 'cc [...] -o git+ && mv git+ git'Ævar Arnfjörð Bjarmason, Mar 7, 2021
  2. Junio C HamanoMar 7, 2021
  3. Ævar Arnfjörð BjarmasonMar 8, 2021
  4. Junio C HamanoMar 8, 2021
  5. Jeff KingMar 8, 2021
  6. 0/5 Makefile: don't die on AIX with open ./gitÆvar Arnfjörð Bjarmason, Mar 29, 2021
  7. 1/5 Makefile: rename objects in-place, don't clobberÆvar Arnfjörð Bjarmason, Mar 29, 2021
  8. Junio C HamanoMar 29, 2021
  9. Junio C HamanoMar 29, 2021
  10. Ævar Arnfjörð BjarmasonMar 29, 2021
  11. Junio C HamanoMar 30, 2021
  12. Ævar Arnfjörð BjarmasonMar 31, 2021
  13. Junio C HamanoMar 31, 2021
  14. 4/5 Makefile: add the ".DELETE_ON_ERROR" flagÆvar Arnfjörð Bjarmason, Mar 29, 2021
  15. Junio C HamanoMar 29, 2021
  16. Ævar Arnfjörð BjarmasonMar 29, 2021
  17. Junio C HamanoMar 29, 2021
  18. Jeff KingMar 30, 2021
  19. Junio C HamanoMar 30, 2021
  20. Jeff KingMar 31, 2021
  21. Junio C HamanoMar 31, 2021
  22. Johannes SchindelinMar 31, 2021
  23. 3/5 Makefile: don't needlessly "rm $@ $@+" before "mv $@+ $@"Ævar Arnfjörð Bjarmason, Mar 29, 2021
  24. Junio C HamanoMar 29, 2021
  25. 2/5 Makefile: rename scripts in-place, don't clobberÆvar Arnfjörð Bjarmason, Mar 29, 2021
  26. Junio C HamanoMar 29, 2021
  27. Ævar Arnfjörð BjarmasonMar 29, 2021
  28. 5/5 Makefile: don't "rm configure" before generating itÆvar Arnfjörð Bjarmason, Mar 29, 2021
  29. 0/6 Makefile: make non-symlink & non-hardlink install saneÆvar Arnfjörð Bjarmason, Mar 29, 2021
  30. 1/6 Makefile: symlink the same way under "symlinks" and "no hardlinks"Ævar Arnfjörð Bjarmason, Mar 29, 2021
  31. Junio C HamanoMar 29, 2021
  32. 5/6 Makefile: use "ln -f" instead of "rm && ln"Ævar Arnfjörð Bjarmason, Mar 29, 2021
  33. Junio C HamanoMar 29, 2021
  34. 4/6 Makefile: make INSTALL_SYMLINKS affect the build directoryÆvar Arnfjörð Bjarmason, Mar 29, 2021
  35. Junio C HamanoMar 29, 2021
  36. Ævar Arnfjörð BjarmasonMar 31, 2021
  37. 6/6 Makefile: add a INSTALL_FALLBACK_LN_CP modeÆvar Arnfjörð Bjarmason, Mar 29, 2021
  38. Junio C HamanoMar 29, 2021
  39. Ævar Arnfjörð BjarmasonMar 31, 2021
  40. Junio C HamanoMar 31, 2021
  41. Ævar Arnfjörð BjarmasonMar 31, 2021
  42. 3/6 Makefile: refactor out "ln || ln -s || cp" patternÆvar Arnfjörð Bjarmason, Mar 29, 2021
  43. Junio C HamanoMar 29, 2021
  44. Jeff KingMar 30, 2021
  45. Junio C HamanoMar 30, 2021
  46. 2/6 Makefile: begin refactoring out "ln || ln -s || cp" patternÆvar Arnfjörð Bjarmason, Mar 29, 2021
  47. Junio C HamanoMar 29, 2021
  48. Junio C HamanoMar 29, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.