Changeset 3262


Ignore:
Timestamp:
Apr 20, 2014, 11:24:46 AM (5 years ago)
Author:
bruno
Message:
  • Change interface of mr_file_read_all_link to returning a hash of hash.
  • When recursing with a hash used, declare it with our so it's available correctly at all levels.
  • mr_file_read_all_link now really returns all the links neeed
Location:
branches/3.2/MondoRescue
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/bin/mr-read-all-link

    r3231 r3262  
    1010use Data::Dumper;
    1111use MondoRescue::File;
     12# For pbdebug
     13use ProjectBuilder::Base;
    1214
    1315=pod
     
    5456=cut
    5557
     58$pbdebug = 2 if ((defined $ARGV[0]) && ($ARGV[0] eq "-v"));
    5659
    5760my $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"));
     61my %h;
    6162
    6263#print Dumper($file);
    6364
    6465foreach 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);
    6768    #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;
    7073    }
    71     print "--\n" if (defined $verbose);
     74    print "--\n" if ($pbdebug >= 1);
    7275}
     76
     77foreach my $l (sort keys %h) {
     78    print "$l\n";
     79}
  • branches/3.2/MondoRescue/lib/MondoRescue/File.pm

    r3229 r3262  
    8989This function returns all the links found for a given file passed as parameter
    9090Example: 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
     91The return value is a hash of all input files pointing to hash of links
    9292
    9393=cut
     
    9696
    9797# TODO: Can be parallelized
    98 my $files;
     98our $files;
    9999
    100100foreach my $f (@_) {
     
    114114            $link = mr_file_normalize($link,"$curdir/$dir");
    115115            # It's a real symlink so handle it
    116             push @{$files->{$f}},"$curdir/$dir";
     116            $files->{$f}->{"$curdir/$dir"} = 1;
    117117            if (substr($link,0,1) eq "/") {
    118118                $curdir = $link;
     
    124124            if ((-e $curdir) && ((! -d $curdir) || (-l $curdir))) {
    125125                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");
    127127                foreach my $k (keys %$h) {
    128                     # At that point there is only one key
    129                     # as there was one param passed to the function.
    130128                    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;
    132132                    }
    133133                }
     134                pb_log(2,"After Return files:\n".Dumper($files)."\n");
    134135            }
    135136        } else {
     
    138139    }
    139140    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}
     143pb_log(1,"mr_file_read_all_link returns:\n".Dumper($files)."\n");
    142144return($files);
    143145}
  • branches/3.2/MondoRescue/t/01-read-all-link.t

    r3243 r3262  
    7373}
    7474    # 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");
     75myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/toto"}, 1, "File link in same dir to itself");
     76myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in same dir to link");
     77myis($h->{"$bd/var/truc"}->{"$bd/var/truc"}, 1, "File link in another absolute dir to itself");
     78myis($h->{"$bd/var/truc"}->{"$bd/usr/bin/perl"}, 1, "File link in another absolute dir to link");
     79myis($h->{"$bd/var/spool/toto"}->{"$bd/var/spool/toto"}, 1, "File link in another relative dir to itself");
     80myis($h->{"$bd/var/spool/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in another relative dir to link");
     81myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/titi"}, 1, "Directory link in same dir to itself");
     82myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in same dir to link");
     83myis($h->{"$bd/var/lib/titi"}->{"$bd/var/lib/titi"}, 1, "Directory link in another relative dir to itself");
     84myis($h->{"$bd/var/lib/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in another relative dir to link");
     85myis($h->{"$bd/var/tutu"}->{"$bd/var/tutu"}, 1, "Directory link in another absolute dir to itself");
     86myis($h->{"$bd/var/tutu"}->{"$bd/var/spool/mail"}, 1, "Directory link in another absolute dir to link");
    8787chdir "/tmp";
    8888exit(0);
Note: See TracChangeset for help on using the changeset viewer.