tmpfiles: add --prefix and --exclude-prefix options

This commit is contained in:
William Hubbs 2013-07-25 00:58:38 -05:00
parent 19579687fd
commit e9189cd8a2

View File

@ -15,6 +15,17 @@
DRYRUN=0 DRYRUN=0
checkprefix() {
n=$1
shift
for x in $@; do
case $n in
${x}*) return 0 ;;
esac
done
return 1
}
warninvalid() { warninvalid() {
printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE" printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE"
error=$(( error+1 )) error=$(( error+1 ))
@ -202,6 +213,8 @@ _Z() {
} }
CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
EXCLUDE=
PREFIX=
FILE= FILE=
fragments= fragments=
# XXX: The harcoding of /usr/lib/ is an explicit choice by upstream # XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
@ -237,6 +250,8 @@ while [ $# -gt 0 ]; do
--clean) CLEAN=1 ;; # TODO: Not implemented --clean) CLEAN=1 ;; # TODO: Not implemented
--verbose) VERBOSE=1 ;; --verbose) VERBOSE=1 ;;
--dryrun|--dry-run) DRYRUN=1 ;; --dryrun|--dry-run) DRYRUN=1 ;;
--exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} " ;;
--prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
esac esac
shift shift
done done
@ -247,7 +262,7 @@ if [ $(( CLEAN )) -eq 1 ] ; then
fi fi
if [ "$CREATE$REMOVE" = '00' ]; then if [ "$CREATE$REMOVE" = '00' ]; then
printf 'usage: %s [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}" printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
exit 1 exit 1
fi fi
@ -297,6 +312,8 @@ for FILE in $tmpfiles_d ; do
[ "$arg" = '-' -o "$arg" = '' ] && arg='' [ "$arg" = '-' -o "$arg" = '' ] && arg=''
set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg" set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg"
[ -n "$EXCLUDE" ] && checkprefix $path $EXCLUDE && continue
[ -n "$PREFIX" ] && ! checkprefix $path $PREFIX && continue
[ "$VERBOSE" -eq "1" ] && echo _$cmd "$@" [ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
_$cmd "$@" _$cmd "$@"
rc=$? rc=$?