Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Dec 2015 03:17:07 +0000 (UTC)
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r291732 - head/share/mk
Message-ID:  <201512040317.tB43H8oY047125@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bdrewery
Date: Fri Dec  4 03:17:07 2015
New Revision: 291732
URL: https://svnweb.freebsd.org/changeset/base/291732

Log:
  DIRDEPS_BUILD: Install new Makefile.depend files atomically.
  
  Sponsored by:	EMC / Isilon Storage Division

Modified:
  head/share/mk/install-new.mk

Modified: head/share/mk/install-new.mk
==============================================================================
--- head/share/mk/install-new.mk	Fri Dec  4 03:17:04 2015	(r291731)
+++ head/share/mk/install-new.mk	Fri Dec  4 03:17:07 2015	(r291732)
@@ -32,9 +32,23 @@ CmpCp= CmpCp() { \
 		cp $$src $$target; \
 	fi; }
 
+# Replace the file if they are different and make a backup if desired
+CmpReplace= CmpReplace() { \
+	src=$$1 target=$$2 _bak=$$3; \
+	if ! test -s $$target || ! cmp -s $$target $$src; then \
+		trap "" 1 2 3 15; \
+		if test -s $$target; then \
+			if test "x$$_bak" != x; then \
+				rm -f $$target$$_bak; \
+				cp -f $$target $$target$$_bak; \
+			fi; \
+		fi; \
+		mv -f $$src $$target; \
+	fi; }
+
 # If the .new file is different, we want it.
 # Note: this function will work as is for *.new$RANDOM"
-InstallNew= ${CmpCp}; InstallNew() { \
+InstallNew= ${CmpReplace}; InstallNew() { \
 	_t=-e; _bak=; \
 	while :; do \
 		case "$$1" in \
@@ -46,7 +60,7 @@ InstallNew= ${CmpCp}; InstallNew() { \
 	for new in "$$@"; do \
 		if test $$_t $$new; then \
 			target=`expr $$new : '\(.*\).new'`; \
-			CmpCp $$new $$target $$_bak; \
+			CmpReplace $$new $$target $$_bak; \
 		fi; \
 		rm -f $$new; \
 	done; :; }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201512040317.tB43H8oY047125>