summaryrefslogtreecommitdiffstats
path: root/share/mk
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2015-12-04 03:17:07 +0000
committerbdrewery <bdrewery@FreeBSD.org>2015-12-04 03:17:07 +0000
commit481bdbbd19066be5232fbe38a6601950575724d0 (patch)
treeb450ac305ef6726b40be485a96fee79925b91847 /share/mk
parent355f30d3b345b3edfe14ff66c64c2afce3ed49f2 (diff)
downloadFreeBSD-src-481bdbbd19066be5232fbe38a6601950575724d0.zip
FreeBSD-src-481bdbbd19066be5232fbe38a6601950575724d0.tar.gz
DIRDEPS_BUILD: Install new Makefile.depend files atomically.
Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'share/mk')
-rw-r--r--share/mk/install-new.mk18
1 files changed, 16 insertions, 2 deletions
diff --git a/share/mk/install-new.mk b/share/mk/install-new.mk
index 469e986..5e95c99 100644
--- a/share/mk/install-new.mk
+++ b/share/mk/install-new.mk
@@ -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; :; }
OpenPOWER on IntegriCloud