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 | |
by AltBlue (Chaplain) on Oct 09, 2001 at 03:08 UTC |