[Pm-utils] symlinks not relative

Dan Nicholson dbn.lists at gmail.com
Wed Apr 30 23:56:01 PDT 2008


On Wed, Apr 30, 2008 at 4:38 PM, Victor Lowther
<victor.lowther at gmail.com> wrote:
> On Wed, 2008-04-30 at 15:22 -0700, Dan Nicholson wrote:
>
> > On Wed, Apr 30, 2008 at 3:00 PM, Till Maas <opensource at till.name> wrote:
>  > >
>  > >  currently the symlinks that are created in pm-utils (pm-suspend ->
>  > >  pm-action, ...) are not relative,. Is it easily possible to change these to
>  > >  be relative symlinks? This would have the advantage, that they would also
>  > >  work, when the root file system is mounted somewhere else than /.
>
>  Indeed, it would.  To do it nicely would take some shell script hackery
>  that I have not taken the time to seriously think about (especially the
>  bit about making it play nice with automake, which is what we would need
>  to do to make it elegant).
...
>  > $ perl -e 'use File::Spec; print
>  > File::Spec->abs2rel("/usr/lib/pm-utils/bin","/usr/sbin"),"\n"'
>  > ../lib/pm-utils/bin
>
>  I would really rather avoid perl if we can.  Any idea how other projects
>  solve this (if they even try)?  It seems like a common enough
>  requirement that the autotools probably have some sort of evil hack that
>  implements it.

Definitely understandable to avoid the perl, but I can't recall having
seen this anywhere referenced in the autotools. Here's something I
wrote as an RPM macro before I stumbled on the above perl. The
formatting blows due to macro-izing it, and there are no comments, but
maybe it will give you some ideas. It worked on most of the corner
cases I could think of, but I seem to remember there was one weird
case where I decided I could live without it. Ultimately I decided I
didn't mind pulling in one line of Perl with a standard module.

%rel_path() %( \
target=$(echo "%{?1}" | sed 's,//*,/,g;s,/*$,,'); \
root=$(echo "%{?2}" | sed 's,//*,/,g;s,/*$,,'); \
[ "$target" = "$root" ] && exit 0; \
comm=$root; \
while :; do \
  uniq=${target#$comm}; \
  case "$uniq" in \
    (/*) break ;; \
    (*) comm=${comm%/*}; \
       if [ -z "$comm" ]; then \
         uniq=$target; \
         break; \
       fi; \
       ;; \
  esac; \
done; \
rel=$(echo "$uniq" | sed 's,/[^/]\\+,../,g'); \
echo "$rel${root#/}${root:+/}"; \
)

--
Dan


More information about the Pm-utils mailing list