2 hopefully useful snippets regarding __subject__

Update: as [id://wog] spotted, my original post was absolutely dumb, with myself reinventing the wheel, this being abs2rel routine from File::Spec module.

symlink converter: transforms absolute symlinks from a directory tree into relative ones. mainly useful for normalizing symlinks in a chrooted environment
usage: $0 <base_directory>

#!/usr/bin/perl -w use strict; use File::Spec (); use File::Find (); my $d = shift || '.'; File::Find::finddepth({wanted => sub { return unless -l; my $rl = readlink $_; print $_,'... '; unlink $_ or print 'error: unlink // ',$!,$/, return; symlink File::Spec->abs2rel($rl,$d), $_ or print 'error: symlink // ',$!,$/, return; print 'OK',$/; }, no_chdir => 1}, $d);

simple relative symlink maker: given a source path and a destination directory, it will create a symlink to the source path in the destination directory with the same basename of the source.
usage: $0 src_path <dest_dir>

#!/usr/bin/perl -w use strict; use File::Spec; my $src = shift or die 'ERROR: source not specified!', $/; my $dest = shift || '.'; chdir $dest or die qq{ouch, cannot chdir to '$dest': $!$/}; $src = File::Spec->abs2rel( $src, $dest ) ; $src =~ m|/([^/]+)$|; symlink $src, $1 or die qq{cannot create symlink: $!$/};

Replies are listed 'Best First'.
Re: rel_path, a relative symbolic links helper
by wog (Curate) on Oct 09, 2001 at 01:03 UTC
    Note that File::Spec's offers a abs2rel method which does a very similar thing. It is more portable -- it will work on the MacOS, VMS, etc. The only difference I can see is that it does not resolve symbolic links before computing the relative path, something that can be easily worked around.
      you are so very right :)) i wish i could --vote myself for this o;-) i never noticed the presence of abs2rel in File::Spec :( ... so, i've updated my previous node to merely show up some hopefully useful things =)

      --
      AltBlue.