mk/pkginstall/files: allow spaces in configuration file names

Fixes PR pkg/42191.
This commit is contained in:
rillig 2020-02-11 01:59:30 +00:00
parent 944799cea6
commit 538c9b877c
5 changed files with 92 additions and 22 deletions

View file

@ -1,4 +1,4 @@
# $NetBSD: bsd.pkginstall.mk,v 1.72 2018/11/30 18:38:20 rillig Exp $
# $NetBSD: bsd.pkginstall.mk,v 1.73 2020/02/11 01:59:30 rillig Exp $
#
# This Makefile fragment is included by bsd.pkg.mk and implements the
# common INSTALL/DEINSTALL scripts framework. To use the pkginstall
@ -60,7 +60,7 @@ _SORTED_VARS.pkginstall= *_SUBST
# The Solaris /bin/sh does not know the ${foo#bar} shell substitution.
# This shell function serves a similar purpose, but is specialized on
# stripping ${PREFIX}/ from a pathname.
_FUNC_STRIP_PREFIX= \
_PKGINSTALL_FUNCS_SH= \
strip_prefix() { \
${AWK} 'END { \
plen = length(prefix); \
@ -69,6 +69,10 @@ _FUNC_STRIP_PREFIX= \
} \
print s; \
}' s="$$1" prefix=${PREFIX:Q}/ /dev/null; \
}; \
\
shquote_backslash() { \
${ECHO} "$$1" | ${SED} 's,[^-A-Za-z0-9.\/_],\\&,g'; \
}
_PKGINSTALL_DIR= ${WRKDIR}/.pkginstall
@ -418,7 +422,7 @@ _INSTALL_DATA_TMPL+= ${_INSTALL_PERMS_DATAFILE}
${_INSTALL_PERMS_DATAFILE}:
${RUN}${MKDIR} ${.TARGET:H}
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${SPECIAL_PERMS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -505,7 +509,7 @@ _INSTALL_RCD_SCRIPTS= ${RCD_SCRIPTS}
privileged-install-hook: _pkginstall-postinstall-check
_pkginstall-postinstall-check: .PHONY
${RUN} p="${DESTDIR}${PREFIX}"; \
${_FUNC_STRIP_PREFIX}; \
${_PKGINSTALL_FUNCS_SH}; \
canon() { f=`strip_prefix "$$1"`; case $$f in [!/]*) f="$$p/$$f"; esac; echo "$$f"; }; \
needargs() { [ $$3 -ge $$2 ] || ${FAIL_MSG} "[bsd.pkginstall.mk] $$1 must have a multiple of $$2 words. Rest: $$4"; }; \
set args ${_INSTALL_RCD_SCRIPTS}; shift; \
@ -540,7 +544,7 @@ _pkginstall-postinstall-check: .PHONY
${_INSTALL_FILES_DATAFILE}:
${RUN}${MKDIR} ${.TARGET:H}
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${_INSTALL_RCD_SCRIPTS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -549,17 +553,19 @@ ${_INSTALL_FILES_DATAFILE}:
egfile="${RCD_SCRIPTS_EXAMPLEDIR}/$$script"; \
${ECHO} "# FILE: $$file cr $$egfile ${RCD_SCRIPTS_MODE}"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${CONF_FILES}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
egfile="$$1"; file="$$2"; \
shift; shift; \
egfile=`strip_prefix "$$egfile"`; \
egfile=`shquote_backslash "$$egfile"`; \
file=`strip_prefix "$$file"`; \
file=`shquote_backslash "$$file"`; \
${ECHO} "# FILE: $$file c $$egfile ${CONF_FILES_MODE}"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${REQD_FILES}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -569,7 +575,7 @@ ${_INSTALL_FILES_DATAFILE}:
file=`strip_prefix "$$file"`; \
${ECHO} "# FILE: $$file cf $$egfile ${REQD_FILES_MODE}"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${CONF_FILES_PERMS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -580,7 +586,7 @@ ${_INSTALL_FILES_DATAFILE}:
file=`strip_prefix "$$file"`; \
${ECHO} "# FILE: $$file c $$egfile $$mode $$owner $$group"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${REQD_FILES_PERMS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -643,7 +649,7 @@ _INSTALL_DATA_TMPL+= ${_INSTALL_DIRS_DATAFILE}
${_INSTALL_DIRS_DATAFILE}:
${RUN}${MKDIR} ${.TARGET:H}
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
exec 1>>${.TARGET}; \
case ${PKG_SYSCONFSUBDIR:M*:Q}${CONF_FILES:M*:Q}${CONF_FILES_PERMS:M*:Q}"" in \
"") ;; \
@ -667,7 +673,7 @@ ${_INSTALL_DIRS_DATAFILE}:
"") ;; \
*) ${ECHO} "# DIR: ${RCD_SCRIPTS_DIR:S/${PREFIX}\///} m" ;; \
esac
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${MAKE_DIRS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -675,7 +681,7 @@ ${_INSTALL_DIRS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# DIR: $$dir m"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${REQD_DIRS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -683,7 +689,7 @@ ${_INSTALL_DIRS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# DIR: $$dir fm"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${OWN_DIRS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -691,7 +697,7 @@ ${_INSTALL_DIRS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# DIR: $$dir mo"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${MAKE_DIRS_PERMS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -700,7 +706,7 @@ ${_INSTALL_DIRS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# DIR: $$dir m $$mode $$owner $$group"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${REQD_DIRS_PERMS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -709,7 +715,7 @@ ${_INSTALL_DIRS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# DIR: $$dir fm $$mode $$owner $$group"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${OWN_DIRS_PERMS}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -770,7 +776,7 @@ ${_INSTALL_INFO_FILES_FILE}: ../../mk/pkginstall/info-files
install-script-data: install-script-data-info-files
install-script-data-info-files:
.if defined(INFO_FILES)
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
if ${TEST} -x ${INSTALL_FILE}; then \
${INFO_FILES_cmd} | \
while read file; do \
@ -826,7 +832,7 @@ _INSTALL_DATA_TMPL+= ${_INSTALL_SHELL_DATAFILE}
${_INSTALL_SHELL_DATAFILE}:
${RUN}${MKDIR} ${.TARGET:H}
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${PKG_SHELL}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -932,7 +938,7 @@ FILES_SUBST+= X11_ENCODINGSDIR=${X11_ENCODINGSDIR:Q}
${_INSTALL_FONTS_DATAFILE}:
${RUN}${MKDIR} ${.TARGET:H}
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${FONTS_DIRS.ttf}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -940,7 +946,7 @@ ${_INSTALL_FONTS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# FONTS: $$dir ttf"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${FONTS_DIRS.type1}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -948,7 +954,7 @@ ${_INSTALL_FONTS_DATAFILE}:
dir=`strip_prefix "$$dir"`; \
${ECHO} "# FONTS: $$dir type1"; \
done
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
set -- dummy ${FONTS_DIRS.x11}; shift; \
exec 1>>${.TARGET}; \
while ${TEST} $$# -gt 0; do \
@ -996,7 +1002,7 @@ ${_INSTALL_ICON_THEMES_DATAFILE}:
.PHONY: install-script-data-icon-themes
install-script-data: install-script-data-icon-themes
install-script-data-icon-themes:
${RUN}${_FUNC_STRIP_PREFIX}; \
${RUN}${_PKGINSTALL_FUNCS_SH}; \
if ${TEST} -x ${INSTALL_FILE}; then \
${ICON_THEMES_cmd} | \
while read theme; do \

View file

@ -0,0 +1,2 @@
Demonstrates that the names of CONF_FILES can contain spaces and that
these can be quoted using backslashes, double quotes or single quotes.

View file

@ -0,0 +1,28 @@
# $NetBSD: Makefile,v 1.1 2020/02/11 01:59:30 rillig Exp $
#
# Requires bmake from 2015 or later, since in previous versions, the .for
# loop did split the variable values strictly on spaces, without taking
# backslashes or quotes into account.
PKGNAME= conf-files-spaces-2020.02.11
CATEGORIES= misc
DISTFILES= # none
COMMENT= Demonstrates spaces in configuration file names
LICENSE= 2-clause-bsd
BUILD_DIRS= # none
EGDIR= share/${PKGBASE}
EGFILES= back\ slash.conf "d quot.conf" 's quot.conf'
.for file in ${EGFILES}
CONF_FILES+= ${EGDIR}/${file} ${PKG_SYSCONFDIR}/${file}
.endfor
do-install:
mkdir ${DESTDIR}${PREFIX}/${EGDIR}
.for file in ${EGFILES}
${INSTALL_DATA} /dev/null ${DESTDIR}${PREFIX}/${EGDIR}/${file}
.endfor
.include "../../mk/bsd.pkg.mk"

View file

@ -0,0 +1,4 @@
@comment $NetBSD: PLIST,v 1.1 2020/02/11 01:59:30 rillig Exp $
share/conf-files-spaces/back slash.conf
share/conf-files-spaces/d quot.conf
share/conf-files-spaces/s quot.conf

View file

@ -0,0 +1,30 @@
# $NetBSD: spec,v 1.1 2020/02/11 01:59:30 rillig Exp $
#
# Up to February 2020, pkgsrc could not handle configuration files with
# spaces in their names.
do_setup() {
$TEST_MAKE deinstall clean
}
do_test() {
PKG_CONFIG=yes $TEST_MAKE install >> "$TEST_OUTFILE"
sysconfdir=`$TEST_MAKE show-var VARNAME=PKG_SYSCONFDIR`
for file in "back slash.conf" "d quot.conf" "s quot.conf"; do
test -f "$sysconfdir/$file" || regress_fail "'$file' not found"
done
PKG_CONFIG=yes $TEST_MAKE deinstall >> "$TEST_OUTFILE"
}
check_result() {
exit_status "0"
output_require ": copying .*/back slash.conf to .*/back slash.conf"
output_require ": copying .*/d quot.conf to .*/d quot.conf"
output_require ": copying .*/s quot.conf to .*/s quot.conf"
}
do_cleanup() {
$TEST_MAKE deinstall clean
}