Changeset 3262 in MondoRescue
- Timestamp:
- Apr 20, 2014, 11:24:46 AM (10 years ago)
- Location:
- branches/3.2/MondoRescue
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/MondoRescue/bin/mr-read-all-link
r3231 r3262 10 10 use Data::Dumper; 11 11 use MondoRescue::File; 12 # For pbdebug 13 use ProjectBuilder::Base; 12 14 13 15 =pod … … 54 56 =cut 55 57 58 $pbdebug = 2 if ((defined $ARGV[0]) && ($ARGV[0] eq "-v")); 56 59 57 60 my $file = mr_file_read_all_link(@ARGV) if (defined $ARGV[0]); 58 59 my $verbose = undef; 60 $verbose = 1 if ((defined $ARGV[0]) && ($ARGV[0] eq "-v")); 61 my %h; 61 62 62 63 #print Dumper($file); 63 64 64 65 foreach my $f (sort keys %$file) { 65 print "$f\n" if ( defined $verbose);66 print "--\n" if ( defined $verbose);66 print "$f\n" if ($pbdebug >= 1); 67 print "--\n" if ($pbdebug >= 1); 67 68 #print Dumper($f); 68 foreach my $l (@{$file->{$f}}) { 69 print "$l\n"; 69 foreach my $l (sort keys $file->{$f}) { 70 print "==" if ($pbdebug >= 1); 71 print "$l\n" if ($pbdebug >= 1); 72 $h{$l} = 1; 70 73 } 71 print "--\n" if ( defined $verbose);74 print "--\n" if ($pbdebug >= 1); 72 75 } 76 77 foreach my $l (sort keys %h) { 78 print "$l\n"; 79 } -
branches/3.2/MondoRescue/lib/MondoRescue/File.pm
r3229 r3262 89 89 This function returns all the links found for a given file passed as parameter 90 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 arraysof links91 The return value is a hash of all input files pointing to hash of links 92 92 93 93 =cut … … 96 96 97 97 # TODO: Can be parallelized 98 my$files;98 our $files; 99 99 100 100 foreach my $f (@_) { … … 114 114 $link = mr_file_normalize($link,"$curdir/$dir"); 115 115 # It's a real symlink so handle it 116 push @{$files->{$f}},"$curdir/$dir";116 $files->{$f}->{"$curdir/$dir"} = 1; 117 117 if (substr($link,0,1) eq "/") { 118 118 $curdir = $link; … … 124 124 if ((-e $curdir) && ((! -d $curdir) || (-l $curdir))) { 125 125 my $h = mr_file_read_all_link($curdir); 126 pb_log(2," File: $curdir - Return:\n".Dumper($h)."\n");126 pb_log(2,"After Return h:\n".Dumper($h)."\n"); 127 127 foreach my $k (keys %$h) { 128 # At that point there is only one key129 # as there was one param passed to the function.130 128 foreach my $l (keys %$k) { 131 push @{$files->{$f}},$k->{$l}; 129 # Use $f as key as we affects all the files 130 # found in recursion to the current managed file 131 $files->{$f}->{$l} = 1; 132 132 } 133 133 } 134 pb_log(2,"After Return files:\n".Dumper($files)."\n"); 134 135 } 135 136 } else { … … 138 139 } 139 140 pb_log(2,"curdir is now: $curdir**\n"); 140 push @{$files->{$f}},$curdir if (-e $curdir); 141 } 141 $files->{$f}->{$curdir} = 1 if (-e $curdir); 142 } 143 pb_log(1,"mr_file_read_all_link returns:\n".Dumper($files)."\n"); 142 144 return($files); 143 145 } -
branches/3.2/MondoRescue/t/01-read-all-link.t
r3243 r3262 73 73 } 74 74 # Got, expected, comment 75 myis( @{$h->{"$bd/usr/bin/toto"}}[0], "$bd/usr/bin/toto", "File link in same dir to itself");76 myis( @{$h->{"$bd/usr/bin/toto"}}[1], "$bd/usr/bin/perl", "File link in same dir to link");77 myis( @{$h->{"$bd/var/truc"}}[0], "$bd/var/truc", "File link in another absolute dir to itself");78 myis( @{$h->{"$bd/var/truc"}}[1], "$bd/usr/bin/perl", "File link in another absolute dir to link");79 myis( @{$h->{"$bd/var/spool/toto"}}[0], "$bd/var/spool/toto", "File link in another relative dir to itself");80 myis( @{$h->{"$bd/var/spool/toto"}}[1], "$bd/usr/bin/perl", "File link in another relative dir to link");81 myis( @{$h->{"$bd/var/spool/titi"}}[0], "$bd/var/spool/titi", "Directory link in same dir to itself");82 myis( @{$h->{"$bd/var/spool/titi"}}[1], "$bd/var/spool/mail", "Directory link in same dir to link");83 myis( @{$h->{"$bd/var/lib/titi"}}[0], "$bd/var/lib/titi", "Directory link in another relative dir to itself");84 myis( @{$h->{"$bd/var/lib/titi"}}[1], "$bd/var/spool/mail", "Directory link in another relative dir to link");85 myis( @{$h->{"$bd/var/tutu"}}[0], "$bd/var/tutu", "Directory link in another absolute dir to itself");86 myis( @{$h->{"$bd/var/tutu"}}[1], "$bd/var/spool/mail", "Directory link in another absolute dir to link");75 myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/toto"}, 1, "File link in same dir to itself"); 76 myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in same dir to link"); 77 myis($h->{"$bd/var/truc"}->{"$bd/var/truc"}, 1, "File link in another absolute dir to itself"); 78 myis($h->{"$bd/var/truc"}->{"$bd/usr/bin/perl"}, 1, "File link in another absolute dir to link"); 79 myis($h->{"$bd/var/spool/toto"}->{"$bd/var/spool/toto"}, 1, "File link in another relative dir to itself"); 80 myis($h->{"$bd/var/spool/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in another relative dir to link"); 81 myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/titi"}, 1, "Directory link in same dir to itself"); 82 myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in same dir to link"); 83 myis($h->{"$bd/var/lib/titi"}->{"$bd/var/lib/titi"}, 1, "Directory link in another relative dir to itself"); 84 myis($h->{"$bd/var/lib/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in another relative dir to link"); 85 myis($h->{"$bd/var/tutu"}->{"$bd/var/tutu"}, 1, "Directory link in another absolute dir to itself"); 86 myis($h->{"$bd/var/tutu"}->{"$bd/var/spool/mail"}, 1, "Directory link in another absolute dir to link"); 87 87 chdir "/tmp"; 88 88 exit(0);
Note:
See TracChangeset
for help on using the changeset viewer.