pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg_alternatives does not allow for comments in ALTERNATIVES file (and the fix for this)



On Thu, Sep 19, 2019, at 15:47, Robert Elz wrote:
>     Date:        Thu, 19 Sep 2019 11:51:13 +0200
>     From:        "Aleksej Lebedev" <root%zta.lk@localhost>
>     Message-ID:  <71ea2e59-0e04-4b08-9287-278127d36209%www.fastmail.com@localhost>
> 
> Assuming this is something that is wanted (
> 
> 	not my call)...
> 
>   | $ git diff .
>   | diff --git a/pkgtools/pkg_alternatives/files/pkg_alternatives.sh 
> b/pkgtools/pkg_alternatives/files/pkg_alternatives.sh
>   | index 56a19b10524..3d794ee83d2 100644
>   | --- a/pkgtools/pkg_alternatives/files/pkg_alternatives.sh
>   | +++ b/pkgtools/pkg_alternatives/files/pkg_alternatives.sh
>   | @@ -56,7 +56,7 @@ action_auto_package() {
>   |      validate_package ${1}
>   |      pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES
>   |  
>   | -    set -- $(cat ${pkg} | sed -e 's# #__dE/lImIt/Er__#g')
>   | +    set -- $(grep -v -e '^[[:space:]]*#' ${pkg} | sed -e 's# 
> #__dE/lImIt/Er__#g')
>   |      while [ ${#} -gt 0 ]; do
>   |          action_auto_wrapper ${1%%__dE/lImIt/Er__*}
>   |          shift
> 
> grep | sed is kind of insane unless there's a very good reason for it.
> 
> (So is the current "cat file | sed" where "sed < file" would do as well,
> except that here "file" contains a glob expression, which doesn't work
> (portably) with redirections, so the current method is correct.)
> 
> It seems possible that the glob might expand into more than one file,
> in which case the grep | sed would end up having grep put file names
> in its output
> 	file1:line without a comment
> 	file1:another
> 	file2:line without comment
> or similar, which doesn't seem ideal, so as a mininum you'd need -h
> as an extra option to avoid that (and I have no idea how portable that
> option is).
> 
> So, keep the cat, and let sed do the work instead of adding grep.
> 
> Something like (untested)
> 
> 	set -- $( cat $pkg |
> 			sed -e '/^[[:space:]]*#/d' \
> 			    -e 's# #__dE/lImIt/Er__#g'  )
> 

Indeed, grep would not work with multiple files and sed can do the job.
Thank you.

--
Aleksej Lebedev


Home | Main Index | Thread Index | Old Index