Changeset 3228 in MondoRescue
- Timestamp:
- Dec 30, 2013, 10:46:39 AM (11 years ago)
- Location:
- branches/3.2/MondoRescue
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/MondoRescue/bin/mr-read-all-link
r3226 r3228 8 8 # 9 9 use strict; 10 use Data::Dumper; 10 11 use MondoRescue::File; 11 12 … … 56 57 my $file = mr_file_read_all_link(@ARGV) if (defined $ARGV[0]); 57 58 59 #print Dumper($file); 60 58 61 foreach my $f (sort keys %$file) { 59 print "$f: $file->{$f}\n"; 62 print "$f\n"; 63 print "--\n"; 64 #print Dumper($f); 65 foreach my $l (@{$file->{$f}}) { 66 print "$l\n"; 67 } 68 print "--\n"; 60 69 } -
branches/3.2/MondoRescue/lib/MondoRescue/File.pm
r3224 r3228 13 13 use Data::Dumper; 14 14 use English; 15 #use File::Basename; 15 use Cwd; 16 use File::Basename; 17 use ProjectBuilder::Base; 16 18 use lib qw (lib); 17 19 … … 24 26 25 27 our @ISA = qw(Exporter); 26 our @EXPORT = qw(mr_file_read_all_link mr_file_process_ldd );28 our @EXPORT = qw(mr_file_read_all_link mr_file_process_ldd mr_file_normalize); 27 29 28 30 =pod … … 37 39 38 40 =head1 USAGE 41 42 =over 4 43 44 =item B<mr_file_normalize> 45 46 This function normalize a path by removing .., . or // in paths given as parameters 47 48 =cut 49 50 $pbdebug = 2; 51 52 sub mr_file_normalize { 53 54 my $f = shift; 55 my $dir = shift || undef; 56 57 # We modify based on the current dir, 58 # except when we're asked to use another one (case of a target link) 59 my $newpath = cwd; 60 $newpath = $dir if (defined $dir); 61 62 return($f) if (not defined $f); 63 64 pb_log(0,"mr_file_normalize file: **$f**\n"); 65 pb_log(0,"mr_file_normalize dir : **$dir**\n") if (defined $dir); 66 67 # Handle case of . at the start in path 68 if ($f =~ /^\.\//) { 69 $f =~ s/^\.\//$newpath\//; 70 } 71 # Handle case of .. at the start in path 72 if ($f =~ /^\.\.\//) { 73 my $dn = dirname(dirname($newpath)); 74 $f =~ s/^\.\.\//$dn\//; 75 } 76 # Now handles .. and . in the middle 77 $f =~ s|([^/]*)/([^/]+)/\.\./([^/]+)|$1/$3|g; 78 $f =~ s|([^/]*)/([^/]+)/\./([^/]+)|$1/$2/$3|g; 79 # Handle double / 80 $f =~ s|//|/|g; 81 82 return($f); 83 } 39 84 40 85 =over 4 … … 44 89 This function returns all the links found for a given file passed as parameter 45 90 Example: mr_file_read_all_link(/lib64) returns (/lib64,/usr/lib64) on a system having a link from /lib64 to /usr/lib64 91 The return value is a hash of all input files pointing to arrays of links 46 92 47 93 =cut … … 50 96 51 97 # TODO: Can be parallelized 52 my %files;98 my $files; 53 99 54 100 foreach my $f (@_) { 55 p rint "Processing $f**\n";56 # Normalize the path if with .. in it or //57 $f = ~ s|([^/]*)/([^/]+)/\.\./([^/]+)|$1/$3|g;58 $f =~ s|//|/|g; 101 pb_log(2,"mr_file_read_all_link: **$f**\n"); 102 # Normalize the path if with .. or . or // in it 103 $f = mr_file_normalize($f); 104 59 105 my @fullpath = split(/\//,$f); 60 106 my $curdir = ""; 61 107 while (@fullpath) { 62 108 my $dir = shift @fullpath; 63 print "curdir is now: $curdir** and dir: $dir**\n"; 64 next if (($dir eq ".") || ($dir eq "")); 109 pb_log(2,"curdir is now: $curdir** and dir: $dir**\n"); 110 next if ($dir eq ""); 111 65 112 my $link = readlink("$curdir/$dir"); 66 113 if (defined $link) { 114 $link = mr_file_normalize($link,"$curdir/$dir"); 67 115 # It's a real symlink so handle it 68 if (defined $files{$f}) { 69 $files{$f} .= "$curdir/$dir|"; 70 } else { 71 $files{$f} = "$curdir/$dir|"; 72 } 116 push @{$files->{$f}},"$curdir/$dir"; 73 117 if (substr($link,0,1) eq "/") { 74 118 $curdir = $link; … … 78 122 $curdir = "$dn/$link"; 79 123 } 80 if (( ! -d $curdir) || (-l $curdir)) {124 if ((-e $curdir) && ((! -d $curdir) || (-l $curdir))) { 81 125 my $h = mr_file_read_all_link($curdir); 82 p rint "File: $curdir - Return:\n".Dumper($h)."\n";126 pb_log(2,"File: $curdir - Return:\n".Dumper($h)."\n"); 83 127 foreach my $k (keys %$h) { 84 $files{$f} .= $h->{$k}."|"; 128 # At that point there is only one key 129 # as there was one param passed to the function. 130 foreach my $l (keys %$k) { 131 push @{$files->{$f}},$k->{$l}; 132 } 85 133 } 86 134 } … … 89 137 } 90 138 } 91 $files{$f} .= "$curdir"; 92 } 93 return(\%files); 139 pb_log(2,"curdir is now: $curdir**\n"); 140 push @{$files->{$f}},$curdir if (-e $curdir); 141 } 142 return($files); 94 143 } 95 144 … … 105 154 sub mr_file_process_ldd { 106 155 107 my %files;156 my $files; 108 157 109 158 foreach my $f (@_) { 159 pb_log(2,"mr_file_process_ldd: **$f**\n"); 110 160 open(CMD,"ldd $f 2> /dev/null |") || die "You need ldd for mindi support"; 111 161 # Format is something like this: … … 121 171 $answer = $orig if ($orig =~ /^\//); 122 172 $answer = $dest if ((defined $dest) && ($dest =~ /^\//)); 123 $files {$answer} = $answer if (defined $answer);173 $files->{$answer} = $answer if (defined $answer); 124 174 } 125 175 } 126 176 close(CMD); 127 177 128 return( \%files);178 return($files); 129 179 } 130 180
Note:
See TracChangeset
for help on using the changeset viewer.