From b7d184d8c08f51bdf046506fe8f95cecd295fe83 Mon Sep 17 00:00:00 2001 From: Michal Vasilek Date: Thu, 7 Apr 2022 20:02:37 +0200 Subject: [PATCH] xbps-src: add vrm function --- Manual.md | 5 +++++ common/environment/setup/vrm.sh | 34 +++++++++++++++++++++++++++++++++ xbps-src | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 common/environment/setup/vrm.sh diff --git a/Manual.md b/Manual.md index 8ec755499bbe7a..ae3cb5a8c7ca0e 100644 --- a/Manual.md +++ b/Manual.md @@ -362,6 +362,11 @@ The following functions are defined by `xbps-src` and can be used on any templat it will default to `pkgname`. The `shell` argument can be one of `bash`, `fish` or `zsh`. +- *vrm()* `vrm [-r] ` + + Wrapper around rm that checks if the file exists and prints a warning if it + doesn't. + > Shell wildcards must be properly quoted, Example: `vmove "usr/lib/*.a"`. diff --git a/common/environment/setup/vrm.sh b/common/environment/setup/vrm.sh new file mode 100644 index 00000000000000..4c5971b8645d7b --- /dev/null +++ b/common/environment/setup/vrm.sh @@ -0,0 +1,34 @@ +# Helper function for calling rm on files and prints a warning if the +# file doesn't exist. + +vrm() { + local ARGS recursive broken + if [ "$1" = "-r" ]; then + recursive=yes + ARGS+=" -r" + shift + fi + + msgfunc=msg_warn + if [ -n "$XBPS_STRICT" ]; then + msgfunc=msg_red + fi + for file in "$@"; do + if [ "$recursive" ] && ! [ -d "$file" ]; then + if [ -n "$XBPS_STRICT" ]; then + broken=yes + fi + $msgfunc "$pkgver: vrm: $file is not a directory\n" + elif [ -e "$file" ]; then + rm $ARGS "$file" + else + if [ -n "$XBPS_STRICT" ]; then + broken=yes + fi + $msgfunc "$pkgver: vrm: $file doesn't exist\n" + fi + done + if [ "$broken" ]; then + return 1 + fi +} diff --git a/xbps-src b/xbps-src index 8488c5a3a49cca..17842cb46cc174 100755 --- a/xbps-src +++ b/xbps-src @@ -217,7 +217,7 @@ $(print_cross_targets) with highest priority order than others. -s - Make vsed warnings errors. + Make some warnings errors. -t Create a temporary masterdir to not pollute the current one. Note that the existing masterdir must be fully populated with binary-bootstrap first.