Bug of /usr/lib/rpm/find-requires (rpm-build-4.0.4-5mdk) in finding scriptlist, caused 
by mdk patch

There's some bugs in /usr/lib/rpm/find-requires from rpm-build-4.0.4-5mdk.
This bug is resulted from the patch, rpm-4.0.4-autoreq.patch.bz2, in
rpm-build-4.0.4-5mdk.src.rpm.
The following is the patch lines that cause this bug.

    # --- Grab the file manifest and classify files.
    filelist=`sed "s/['\"]/\\\&/g"`
    exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script) " | \
      grep ":.*executable" | cut -d: -f1`
   -scriptlist=`echo $filelist | xargs -r file | \
   +scriptlist=`echo $filelist | grep -v /usr/doc | grep -v /usr/share/doc | xargs -r 
file | \
      egrep ":.* (commands|script) " | cut -d: -f1`
    liblist=`echo $filelist | xargs -r file | \
      grep ":.*shared object" | cut -d : -f1`

Now, first assume that the input from stdin is as follow.

   /usr/bin/some_script.pl
   /usr/doc/some_doc

By the statement, filelist=`sed "s/['\"]/\\\&/g"`, the input lines passed via
stdin will be turned into only one line and be kept in $filelist,
$filelist == "/usr/bin/some_script.pl /usr/doc/some_doc".
The bug will occur when this whole one line be grepped out by the statement,
grep -v /usr/doc | grep -v /usr/share/doc, so that the /usr/bin/some_script.pl
won't be detected as a script as it should be.

One solution is to use the statement, xargs -r --max-args=1, to turn the
$filelist into lines as follow.

   scriptlist=`echo $filelist | xargs -r --max-args=1 | grep -v /usr/doc | grep -v 
/usr/share/doc | xargs -r file | \
      egrep ":.* (commands|script) " | cut -d: -f1`

But from my experiment, the option, --max-args=1, will cause xargs to
run very slow.

Another faster solution is

   scriptlist=`echo " $filelist" | sed 's| /usr\(/share\)\?/doc[^ ]*||g' | xargs -r 
file | \
      egrep ":.* (commands|script) " | cut -d: -f1`

Note the leading space in " $filelist", which is important in detecting
the beginning of each filename.

>From my experiment, the second solution runs about 2.25 times faster than
the first solution.
But the first solution is less complex, and more elegant.


Reply via email to