Created
May 23, 2022 14:37
-
-
Save ginkgomzd/a2b95a3f278fc635a41469dd2642724f to your computer and use it in GitHub Desktop.
Gnu Make Safe rm File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # # | |
# Manage alternate files by linking different versions to the canonical file name. | |
# # # | |
define safe-unlink-file | |
@# File is not a link, so back-up | |
@#$(or $(shell test -L $1 && echo 'TRUE'), $(call backup-file,$1)) | |
@# File does not exist, or try to remove | |
@#$(if $(shell (test -L $1 || test -e $1) && echo 'TRUE'), $(shell rm -f $1)) | |
endef | |
define backup-file | |
@# Abort if back-up location already exists | |
@#$(and $(shell test -f $1.tmp && echo 'ERROR'), \ | |
$(error Can not back-up $1, aborting)) | |
@# Back-up, unless the file does not exist | |
@#$(or $(shell test ! -e $1 && echo 'TRUE'), \ | |
$(shell mv $1 $1.tmp && echo 'Backed-up to $1.tmp')) | |
endef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment