Re: finding a package name given a filename
Antti-Juhani Kaijanaho <gaia@iki.fi> writes:
> On Sun, Nov 29, 1998 at 03:51:30PM -0500, servis@purdue.edu wrote:
> > The problem with a lot of packages is that the executable is linked
> > from a shorter name, and the links are not part of the package but are
> > created in the postinst scripts. The xemacs example is a really good
> > one.
> >
> > /usr/bin/xemacs -> /etc/alternatives/xemacs
> > /etc/alternatives/xemacs -> /usr/bin/xemacs20
> > /usr/bin/xemacs20 -> /etc/alternatives/xemacs20
> > /etc/alternatives/xemacs20 -> /usr/bin/xemacs-20.4-nomule (finally!!!)
> >
> > So doing a 'dpkg -S /usr/bin/xemacs' would not work because
> > /usr/bin/xemacs is actually not in the xemacs20-nomule package but is
> > created after the package is extracted.
>
> I was thinking about this, tried to find a utility to chase a symbolic
> link to a real file, but failed. I even asked if a local Unix guru
> knew one. He didn't.
>
> So I wrote one. Here's a sample session with it:
>
> ajk@ugh[22:25:31]:~$ dpkg -S `chase /usr/bin/xemacs`
> xemacs20-nomule: /usr/bin/xemacs-20.4-nomule
> ajk@ugh[22:26:16]:~$
>
> The `chase' here is my small utility. Basically it takes a file name
> and finds the name of the real file it refers to, recursively
> dereferencing all the symlinks it encounters.
>
> The source tarball (with a copy of GNU GPL and all the Autoconf bells
> and whistles) is currently 28kB. If anyone is interested, I might
> upload it somewhere (probably metalab aka sunsite), or even generate a
> .deb of it (though I can't upload it to Debian yet, as I'm still
> waiting for my developer status application to be fully processed).
Here is a short perl program that seems to do the same thing. Note that
it doesn't have much error checking.
----- script start (whatever you want to call it) -----------
#!/usr/bin/perl -w
# follow down symbolic links
if ($#ARGV == -1) {
print "usage: $0 <symbolic link>\n";
exit 1;
}
for ($f = $ARGV[0]; -l $f; $f = readlink($f)) { }
print "destination doesn't exist: " if ! -e $f;
print "$f\n";
------- script end ----------------
--
Carl Johnson carlj@peak.org
Reply to: