/usr/vsa -> /root/site/tools/gauv /usr/vsa/pkgs/python3/3.6.3a -> 3.6.3 #### /usr/ /usr/vsa /root/ /root/site /root/site/tools /root/site/tools/gauv /root/site/tools/gauv/pkgs /root/site/tools/gauv/python3 /root/site/tools/gauv/python3/3.6.3a /root/site/tools/gauv/python3/3.6.3 /root/site/tools/gauv/python3/3.6.3/bin /root/site/tools/gauv/python3/3.6.3/bin/python3.6 #### my @arr; foreach my $c (split("/", $current_path)) { if ($c eq "") { next; } $res = "$res/$c"; push(@arr,$res); } my @checked_links; while (1) { my $old = ""; my $new = ""; foreach my $c (@arr) { if (grep("/^$c/",@checked_links)) { next; } if (-l $c) { my $link = readlink($c); my $res; $old = $c; if (index($link,"/") == -1) { my $dirname = dirname($c); my $basename = basename($c); $res = "$dirname/$link"; } else { $res = $link; } unshift(@arr,$res); $new = $link; last; } } if ($old ne "") { for (my $i = 0; $i < scalar(@arr); $i++) { if (@arr[$i] eq $old) { next; # ignore } if (index(@arr[$i],$old) == -1) { next; } $changed = 1; @arr[$i] =~ s/$old/$new/; } push(@checked_links,$old); } if ($changed == 0) { last; } }