Commit Graph

40 Commits

Author SHA1 Message Date
Alexey Tourbin
56a9571e4a find-package (FindByPath): new function LinkIsAlternative()
This will also check if the link is not owned by any package,
but the path is provided by some package.

$ rpm -qf /usr/bin/python
warning: file /usr/bin/python is not owned by any package
$ rpm -q --whatprovides /usr/bin/python
python-base-2.4.4-alt13
$

This looks very much like an alternative, ESPECIALLY if an intermediate
path component, which is a link to directory (python is not the case).

This new condition is disabled, only a warning is issued.
We'll see if it should be enabled.
2007-11-21 15:32:20 +03:00
Alexey Tourbin
377a8491df find-package (FindByPath): use CanonPath again
Note that alternative path may also require non-blind canonicalization (in
very pathological cases), for which I also use CanonPath.

(old behaviour, wrong)
$ sudo ln -s share /usr/bare
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/bare/libtool/config.guess'
/usr/bare/libtool
sh: script: alternative /usr/bare/libtool prevents /usr/bare/libtool/config.guess dependency resolution
$

(new behaviour, good)
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/bare/libtool/config.guess'
/usr/share/libtool
sh: script: alternative /usr/share/libtool prevents /usr/bare/libtool/config.guess dependency resolution
$
2007-11-18 06:56:52 +03:00
Alexey Tourbin
5b353de0eb find-package (FindByPath): rewrite without CanonPath, use two-pass canonicalization 2007-11-17 17:03:04 +03:00
Alexey Tourbin
2bf12baa21 find-package (FindByPath): implemented smart check for alternatives, cf. bug #13374
Some examples.

1)
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool'
/usr/share/libtool
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/'
/usr/share/libtool
$

This shows that alterntaives check is no longer restricted to deficient
	readlink "$rep" |grep '^/etc/alternatives/'
logic.  Old behaviour was:

$ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool'
/usr/share/libtool
$ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool/'
sh: script: checking contents_index_all for /usr/share/libtool-1.5
sh: script: /usr/share/libtool-1.5 -> libtool_1.5 (via contents_index_all)
libtool_1.5
$

2)
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../autoconf'
/usr/share/autoconf
/usr/share/libtool
$

This shows that any number of alternatives can be resolved within a single path.

3)
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/config.guess'
/usr/share/libtool
sh: script: alternative /usr/share/libtool prevents /usr/share/libtool/config.guess resolution
$

This shows that we cannot resolve paths under alternatives directory.

4)
$ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../../bin/perl'
/usr/share/libtool
perl-base
$

This shows that we actually CAN resolve paths which are not under alternatives directory.
2007-11-17 15:04:06 +03:00
5b9096b561 scripts/*.in: s|/usr/lib/rpm/|@RPMCONFIGDIR@/|g 2007-11-10 20:46:59 +00:00
Alexey Tourbin
3064082899 find-package (FindByName): better check for maybe_function 2007-10-09 12:30:05 +04:00
Alexey Tourbin
7d68978688 find-package (FindByPath): ignore /dev/* /proc/* /sys/* dependencies 2007-09-23 01:23:34 +04:00
Alexey Tourbin
d9b38d645f find-package (FindByPath): render $RPM_BUILD_DIR* dependencies invalid 2007-09-21 15:58:05 +04:00
Alexey Tourbin
8dd5a961e8 find-package (FindByPath): consider (not-so-) broken symbolic links inside RPM_BUILD_ROOT 2007-09-19 14:16:01 +04:00
Alexey Tourbin
d74f8d9a69 find-package (findByName): replaced /usr/bin/which with custom shell code
This is to address a few problems:

1) When checking RPM_BUILD_ROOT, st_mode test performed by /usr/bin/which
is not quite reliable.  Files can be packaged with different %attr mode.

2) When checking RPM_BUILD_ROOT, there could be symbolic links there
which are (not-so-) broken.

3) When checking host system, files like /sbin/init (which is 0700)
are effectively bypassed by /usr/bin/which.

4) There's an ongoing practice of placing shell function libraries
under /usr/bin, e.g. /usr/bin/git-sh-setup.  These files are sourced
from within shell scripts and need not be executable at all.

This leads me to the point that permission check, which is performed by
/usr/bin/which, is not needed at all.  Note that things are getting more like
contents_index_bin search.  And for RPM_BUILD_ROOT, we do not even require
strong stat-wise file existence.

I like this new term: "strong stat-wise file existence".
It's awesome.
2007-09-19 12:57:08 +04:00
Alexey Tourbin
3925c4c392 find-package (FindByName): manage "not found" verbosity 2007-09-19 11:08:53 +04:00
Alexey Tourbin
a1e07a6d21 find-package (FindByName): added sbin-ish paths under /etc 2007-09-19 10:33:12 +04:00
Alexey Tourbin
d03deaf0fa find-package: implemented different PATHs for user and root code (the */sbin scripts)
also appended /usr/games to both user and root PATHs
2007-09-19 00:17:53 +04:00
Alexey Tourbin
7ece64adc3 find-package (FindPackage): unquoted $valid case paterns 2007-09-12 20:07:43 +04:00
Alexey Tourbin
e5f015d831 find-package (FindPackage): fixed shell syntax (D'oh!) 2007-09-12 19:34:01 +04:00
Alexey Tourbin
4eb4ccf490 find-package: fixed Verbose message for contents_index_bin 2007-09-12 19:28:46 +04:00
Alexey Tourbin
2b1c36538f find-package: implemented protection against shell metacharacters and evil paths
There are two possibilities for protection:
1) we should protect at least from very evil shell metacharacters,
like [$*], and also from [:cntrl:] (e.g. newline).
2) we can provide an exhaustive list of characters that are valid
for non-evil pathnames and commands, and issue mandatory warning
if the command or path appears to be evil.

I chose the latter approach.
Valid character range is 'A-Za-z0-9/@=.,:_+-'.

Note that (almost) all files from our base build system
are valid paths:

$ valid='A-Za-z0-9/@=.,:_+-'
$ hsh-run -- rpm -qal |grep "[^$valid]"
/usr/bin/[
/usr/share/man/man1/[.1.bz2
(contains no files)
(contains no files)
$

Later we'll see if the range of valid characters needs to be extended.
2007-09-10 13:32:26 +04:00
Alexey Tourbin
650b0fc0c1 find-package (FindByPath): use CanonPath before contens_index search
I see that this can add SOME problems if e.g. /usr is relocated
to /storage/usr in the build environment.  This is because CanonPath
follows symlinks for dirname.

But I argue that it is safe for hasher, and it fixes some problems
with contents_index search which is used only in the hasher (by default).

I also argue that, even if /usr is relocated, this is not going to be a BIG
problem, because it is not going to produce unmet dependencies (well, most
of the time).  This is because 'rpm -qf' will work as expected in that screwed
build environment.
2007-08-27 21:27:05 +04:00
Alexey Tourbin
71c3d7908d find-package (FindByName): in ambigous case, first check if [ path = pkg ] 2007-08-10 16:10:58 +04:00
Alexey Tourbin
bd368155cd find-package (FindByPath): discard rpmquery stderr 2007-08-08 02:54:04 +04:00
Alexey Tourbin
968016ffdc find-package: added description atop 2007-08-08 00:49:48 +04:00
Alexey Tourbin
7c7eccde32 find-package (FindByName): added more comments, for casual readers 2007-08-08 00:28:55 +04:00
Alexey Tourbin
706ff5d5ec find-package: more comments for RPM_FINDPACKAGE_PATH processing 2007-08-07 22:59:50 +04:00
Alexey Tourbin
91b7ebe4c6 find-package: added comments to RPM_FINDPACKAGE_PATH awk script 2007-08-07 22:41:19 +04:00
Alexey Tourbin
c9dbb383f6 find-package: manage verbosity with 'local Verbose' variable
When something goes not as good as we would like, we should
be able to increase verbosity locally for this particular case.

Old behaviour:

$ sh -efu -c '. /usr/lib/rpm/find-package; RPM_PKG_CONTENTS_INDEX_ALL=/etc/passwd FindPackage myscript /bin/cat'
sh: myscript: checking contents_index_all for /bin/cat
coreutils
$

In this example I pretend that /bin/cat lookup failed against
contents_index_all.  The problem here is that, once we know about
a "strange thing" happening, we also want to know the end of the story.
Where does coreutils come from?  That is the question.

New behaviour:

$ sh -efu -c '. /usr/lib/rpm/find-package; RPM_PKG_CONTENTS_INDEX_ALL=/etc/passwd FindPackage myscript /bin/cat'
sh: myscript: checking contents_index_all for /bin/cat
sh: myscript: /bin/cat -> coreutils (via rpmdb)
coreutils
$

When "strange things" happen, I increase verbosity locally,
until the "strange thing" is resolved.  I use 'local Verbose=Info'
approach to increase verbosity.  Since shell has dynamic variables
(with visibility bound to function-call stack), this is just what
we need.

Strange things are:
- in FindByPath:
  + contents_index_all search
- in FindByName:
  + ambiguous contents_index_bin search
    (the same command under e.g. /sbin and /usr/bin)
  + ambiguous /usr/bin/which search (ditto)
2007-08-07 22:17:58 +04:00
Alexey Tourbin
a2090d8dd9 find-package (FindPackage): enhanced path vs. command validation
Also increased verbosity for invalid pathnames and/or commands.
2007-08-07 20:43:02 +04:00
Alexey Tourbin
3f764319ec find-package (FindByPath): enhanced contents_index search
In FindByPath, we should always check contents_index_bin first.
It is not quite expensive, and we make no assumptions which path
entries it may contain (our contents_index_bin, in addition
to standard *bin/ paths, also has /etc entries).

However, if contents_index_bin lookup fails, we may or may
not want to proceed with very expensive contents_index_all
search.  We assume that, if contents_index_bin lookup actually
has take place for some standard *bin/ path, then there is simply
no need to proceed with contents_index_all.

Now we also assume that contents_index_all file can be possibly
gzipped (I use "gzip -cdfq" for "zcat or cat", found in zgrep).

Also increased verbosity (Verbose to Info) for contents_index_all
messages, since it is expensive and it is a means of "last resort"
to finding something strange before giving up, which is quite worth
to note about.

Also increased verbosity for "raw, not found" dependencies,
since they are likely to become unmet.
2007-08-07 19:58:35 +04:00
Alexey Tourbin
5909f93e30 find-package (FindByName): optimized awk script
It looks like that, unlike in perl, pattern matching in awk is very slow.
Perhaps they just don't have regexp engine hackers like Larry Wall or
Ilya Zakharevich (or, most recently, Yves Orton aka demerphq).

That's okay, since I can rewrite the script without pattern matching at all.
That is, I don't have to split each index line into dir+basename, because
I can prepare all valid absolute pathnames in advance.

Old speed:

$ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'`
shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index)
shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index)
shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index)
shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index)
shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index)
shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index)
shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index)
shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index)
shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index)
shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index)
shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index)
shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index)
shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index)
shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index)
rpm-utils
/usr/lib/rpm/shell.req -v /dev/stdin <<<   5.37s user 0.11s system 96% cpu 5.683 total
$

New speed:

$ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'`
shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index)
shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index)
shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index)
shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index)
shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index)
shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index)
shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index)
shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index)
shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index)
shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index)
shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index)
shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index)
shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index)
shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index)
rpm-utils
/usr/lib/rpm/shell.req -v /dev/stdin <<<   0.34s user 0.10s system 88% cpu 0.499 total
$

More than ten times faster, wow!
I didn't know regexp engine could be that slow, really.
2007-03-12 15:06:11 +03:00
Alexey Tourbin
b1b2fab77c find-package (FindPackage): require either absolute path or no slashes 2007-03-12 15:06:10 +03:00
Alexey Tourbin
47fe2b2b3f find-package (FindByName): if the index search detects real conflict, try /usr/bin/which first
E.g. if the content index search detected something like

	/usr/bin/arpsend -> arpsend
	/usr/sbin/arpsend -> vzctl

then we should consult the host system first.  There's a good chance
that the right package, either arpsend or vzctl, IS installed, and
other candidate packages are NOT installed.  However, if /usr/bin/which
cannot find any candidate, we should reconsult the index again.
2007-03-12 15:06:05 +03:00
Alexey Tourbin
83e2b0cfe7 find-package: introduced RPM_FINDPACKAGE_PATH, which makes PATH search fully configurable
$ RPM_FINDPACKAGE_PATH=/usr/bin /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: /dev/stdin: arpsend indexed by: /usr/bin/arpsend -> arpsend, /usr/sbin/arpsend -> vzctl
shell.req: /dev/stdin: arpsend -> /usr/bin/arpsend -> arpsend (via content index)
arpsend
$ RPM_FINDPACKAGE_PATH=/usr/sbin /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: /dev/stdin: arpsend indexed by: /usr/sbin/arpsend -> vzctl, /usr/bin/arpsend -> arpsend
shell.req: /dev/stdin: arpsend -> /usr/sbin/arpsend -> vzctl (via content index)
vzctl
$

Also added %add_findpackage_path() and %set_findpackage_path() to platform.in.
2007-03-12 15:06:04 +03:00
Alexey Tourbin
f060b30e6c find-package (FindByName): enhanced content index part
Old behaviour:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: arpsend -> /usr/sbin/arpsend -> vzctl (via content index)
vzctl
$

New behaviour:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: /dev/stdin: arpsend indexed by: /usr/bin/arpsend -> arpsend, /usr/sbin/arpsend -> vzctl
shell.req: /dev/stdin: arpsend -> /usr/bin/arpsend -> arpsend (via content index)
arpsend
$ /usr/lib/rpm/shell.req -v /dev/stdin <<<ifup
shell.req: /dev/stdin: ifup indexed by: /sbin/ifup -> etcnet, /sbin/ifup -> net-scripts
shell.req: /dev/stdin: ifup -> /sbin/ifup -> /sbin/ifup (raw, ambiguous, via content index)
/sbin/ifup
$
2007-03-12 15:06:03 +03:00
Alexey Tourbin
b208a5725d find-package (FindByPath): enhanced content index part
There's a problem with content index:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</sbin/ifup
shell.req: /dev/stdin: /sbin/ifup -> etcnet (via content index)
etcnet
$ grep /sbin/ifup ~tmp/build/cache/contents/contents_index_bin
/sbin/ifup      etcnet
/sbin/ifup      net-scripts
$

After this change:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</sbin/ifup
shell.req: /dev/stdin: /sbin/ifup indexed by: etcnet net-scripts
shell.req: /dev/stdin: /sbin/ifup -> /sbin/ifup (raw, ambiguous, via content index)
/sbin/ifup
$

Also improved diagnostics and updated copyright statement.
2007-03-12 15:06:02 +03:00
Alexey Tourbin
5852768964 find-package (FindByName): enhanced /usr/bin/which part
There's been a few problems.

1) ~/bin should not be checked.

$ /usr/lib/rpm/shell.req -v /dev/stdin <<<vim
warning: no package provides /home/at/bin/vim
shell.req: /dev/stdin: vim not found (skip)
$

Fortunately /usr/bin/which has --skip-tilde option.

2) Check for /etc/alternatives was missing.

$ PATH=/bin:/usr/bin /usr/lib/rpm/shell.req -v /dev/stdin <<<vim
shell.req: /dev/stdin: vim -> /usr/bin/vim -> vim-X11
vim-console
vim-enhanced (via rpmdb)
vim-X11
vim-console
vim-enhanced
$

This is why FindByName should ultimately call FindByPath.
After this change, it works just fine:

$ scripts/shell.req.in -v /dev/stdin <<<vim
shell.req.in: /dev/stdin: vim -> /usr/bin/vim -> ... (via which)
shell.req.in: /dev/stdin: /usr/bin/vim -> /usr/bin/vim (alternative)
/usr/bin/vim
$

Also enabled /usr/bin/which --all option and added diagnostics
for really ambiguous cases.
2007-03-12 15:06:00 +03:00
Alexey Tourbin
8d2821443d find-package: factored FindByPath() and FindByName()
Actually if you think about it a few hours or so... you may come to
know that FindByName() should ultimately call FindByPath().  But this
will be the next commit.
2007-03-12 15:05:59 +03:00
Alexey Tourbin
f9a7e6dea2 find-package: if some path is provided by two or more rpmdb packages, output raw dependence
Here is the problem:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</usr/bin/openssl-config
shell.req: /dev/stdin: /usr/bin/openssl-config -> libssl-devel<STDERR-NEWLINE>
openssl (via rpmdb)
libssl-devel
openssl
$

Here is the solution:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</usr/bin/openssl-config
shell.req: /dev/stdin: /usr/bin/openssl-config provided by: libssl-devel openssl
shell.req: /dev/stdin: /usr/bin/openssl-config -> /usr/bin/openssl-config (raw)
/usr/bin/openssl-config
$

Note that this new behaviour now matches content index search:

$ grep openssl-config ~tmp/build/cache/contents/contents_index_bin
/usr/bin/openssl-config /usr/bin/openssl-config
$
2007-03-12 15:05:58 +03:00
Alexey Tourbin
ed12439edd scripts/find-package.in: added verbosity
Now it works like this:

$ /usr/lib/rpm/shell.req -v /usr/bin/buildreq
shell.req: /usr/bin/buildreq: cat -> /bin/cat -> coreutils (via rpmdb)
shell.req: /usr/bin/buildreq: cmp -> /usr/bin/cmp -> diffutils (via rpmdb)
shell.req: /usr/bin/buildreq: function(Info) not found (skip)
shell.req: /usr/bin/buildreq: function(show_help) not found (skip)
shell.req: /usr/bin/buildreq: function(show_usage) not found (skip)
shell.req: /usr/bin/buildreq: rm -> /bin/rm -> coreutils (via rpmdb)
shell.req: /usr/bin/buildreq: sed -> /bin/sed -> sed (via rpmdb)
coreutils
diffutils
sed
$

It looks like there's a problem with function(Info) here.
Verbosity is a good thing.
2007-03-11 15:00:25 +03:00
Alexey Tourbin
2bce0efdba scripts/find-package.in: adapted for empty RPM_BUILD_ROOT and `sh -u'
Note: this is non-essential change, so I won't update copyright notice.
2007-03-11 15:00:22 +03:00
5416277102 Removed cvsid tags. 2006-05-14 17:05:34 +04:00
ebc53cf631 use functions 2003-11-09 16:47:45 +00:00