{ "/": { "type": "dir", "files": [ { "usr": { "type": "dir", "files": [ { "vsa": { "type": "link-dir", "source": "/root/site/tools/gauv" } } ] } }, { "root": { "type": "dir", "files": [ { "site": { "type": "dir", "files": [ { "tools": { "type": "dir", "files": [ { "gauv": { "type": "dir", "files": [ { "pkgs": { "type": "dir", "files": [ { "python3": { "type": "dir", "files": [ { "3.6.3a": { "type": "dir-link", "source": "/usr/vsa/pkgs/python3/3.6.3" } }, { "3.6.3": { "type": "dir", "links": [ { "lib": { "type": "dir", "links": [] } }, { "bin": { "type": "dir", "links": [] } } ] } } ] } } ] } } ] } } ] } } ] } } ] } } ] } } #### foreach my $f (@arr) { if (-l $f) { print($f, " is a link to ",readlink($f) , "\n"); my @a = split("/",$f); my $result; my $counter = 0; my $last_files_block = $st{"/"}{"files"}; while (1) { unless ($counter < scalar(@a)) { last; } my $x = $a[$counter]; if ($x eq '') { $counter += 1; next; } if ($counter + 1 == scalar(@a)) { if (-f $f) { my $found = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $found = 1; last; } } if ($found == 0) { my %vsaaa = ("type" => "link-file", "source" => readlink($f)); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); } my $last = $f; while (1) { my $c = readlink($last); if (-l $c) { $last = $c; if (index($c,"/") != -1) { push(@arr,$c); } else { my $found1 = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $found = 1; last; } } if ($found1 == 0) { my %vsaaa = ("type" => "file"); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); } } } else { if (index($c,"/") != -1) { push(@arr,$c); } else { my $found1 = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $found = 1; last; } } if ($found1 == 0) { my %vsaaa = ("type" => "file"); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); } } last; } } } if (-d $f) { my $found = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $found = 1; last; } } if ($found == 0) { my $n = readlink($f); if (index($n,"/") == -1) { my $dirname = dirname($f); $n = "$dirname/$n"; #TODO: what if relative? } my %vsaaa = ("type" => "dir-link", "source" => $n); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); } } last; } my $found = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $last_files_block = $v->{$x}{"files"}; $counter += 1; $found = 1; last; } } if ($found == 0) { my %vsaaa = ("type" => "dir", "files" => [] ); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); $last_files_block = $vsaaa{"files"}; $counter += 1; } } } elsif (-f $f) { print($f, " is a file\n"); my @a = split("/",$f); my $result; my $counter = 0; my $last_files_block = $st{"/"}{"files"}; while (1) { unless ($counter < scalar(@a)) { last; } my $x = $a[$counter]; if ($x eq '') { $counter += 1; next; } if ($counter + 1 == scalar(@a)) { my $found = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $found = 1; last; } } if ($found == 0) { my %vsaaa = ("type" => "file"); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); } last; } my $found = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { $last_files_block = $v->{$x}{"files"}; $counter += 1; $found = 1; last; } } if ($found == 0) { my %vsaaa = ("type" => "dir", "files" => [] ); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); $last_files_block = $vsaaa{"files"}; $counter += 1; } } } elsif (-d $f) { print($f, " is a dir\n"); my @a = split("/",$f); my $result; my $counter = 0; my $last_files_block = $st{"/"}{"files"}; while (1) { unless ($counter < scalar(@a)) { last; } my $x = $a[$counter]; if ($x eq '') { $counter += 1; next; } my $found = 0; my $found_link = 0; foreach my $v (@{$last_files_block}) { if (defined($v->{$x})) { if ($v->{$x}{"type"} eq "dir-link" || $v->{$x}{"type"} eq "link-file") { $found_link = 1; last; } $last_files_block = $v->{$x}{"files"}; $counter += 1; $found = 1; last; } } if ($found_link == 1) { last; } if ($found == 0) { my %vsaaa = ("type" => "dir", "files" => [] ); my %st1 = ($x => \%vsaaa ); push(@{$last_files_block}, \%st1); $last_files_block = $vsaaa{"files"}; $counter += 1; } } } else { #TODO: When can it happen other than path does not exist or permission denied? print($f, " is a special\n"); } }