]> git.sur5r.net Git - bacula/bacula/blobdiff - regress/scripts/diff.pl
regress: Turn on accurate in SS_SQLJob
[bacula/bacula] / regress / scripts / diff.pl
index 013632443374448cd78d3d607b1b9ca49d3c9943..bf217cd60c8886716683f4ff17a8b8a5f08570c0 100755 (executable)
@@ -6,7 +6,7 @@
 
 =head2 USAGE
 
-    diff.pl -s source -d dest [--acl | --attr | --wattr]
+    diff.pl -s source -d dest [-e exclude ] [--acl | --attr | --wattr]
 
 =cut
 
@@ -21,17 +21,21 @@ use Data::Dumper;
 use Cwd;
 use POSIX qw/strftime/;
 
-my ($src, $dst, $help, $acl, $attr, $wattr, $dest_attrib, $src_attrib);
+my ($src, $dst, $help, $acl, $attr, $wattr, 
+    $dest_attrib, $src_attrib, $mtimedir);
 my %src_attr; 
 my %dst_attr;
+my @exclude;
 my $hash;
 my $ret=0;
 
-GetOptions("src=s"   => \$src,  # source directory
-           "dst=s"   => \$dst,  # dest directory
-           "acl"     => \$acl,  # acl test
-           "attr"    => \$attr, # attributes test
-           "wattr"   => \$wattr,# windows attributes
+GetOptions("src=s"   => \$src,        # source directory
+           "dst=s"   => \$dst,        # dest directory
+           "acl"     => \$acl,        # acl test
+           "attr"    => \$attr,       # attributes test
+           "wattr"   => \$wattr,      # windows attributes
+           "mtime-dir" => \$mtimedir, # check mtime on directories
+           "exclude=s@" => \@exclude, # exclude some files
            "help"    => \$help,
     ) or pod2usage(-verbose => 1, 
                    -exitval => 1);
@@ -48,7 +52,7 @@ my $md5 = Digest::MD5->new;
 
 my $dir = getcwd;
 
-chdir($src) or die "E: Can't access to $src";
+chdir($src) or die "ERROR: Can't access to $src";
 $hash = \%src_attr;
 find(\&wanted_src, '.');
 
@@ -59,7 +63,7 @@ if ($wattr) {
 
 chdir ($dir);
 
-chdir($dst) or die "E: Can't access to $dst";
+chdir($dst) or die "ERROR: Can't access to $dst";
 $hash = \%dst_attr;
 find(\&wanted_src, '.');
 
@@ -69,7 +73,7 @@ if ($wattr) {
 
     if (lc($src_attrib) ne lc($dest_attrib)) {
         $ret++;
-        print "E: Differences between windows attributes\n",
+        print "diff.pl ERROR: Differences between windows attributes\n",
               "$src_attrib\n=========\n$dest_attrib\n";
     } 
 }
@@ -81,7 +85,7 @@ foreach my $f (keys %src_attr)
 {
     if (!defined $dst_attr{$f}) {
         $ret++;
-        print "E: Can't find $f in dst\n";
+        print "diff.pl ERROR: Can't find $f in dst\n";
 
     } else {
         compare($src_attr{$f}, $dst_attr{$f});
@@ -93,11 +97,11 @@ foreach my $f (keys %src_attr)
 foreach my $f (keys %dst_attr)
 {
     $ret++;
-    print "E: Can't find $f in src\n";
+    print "diff.pl ERROR: Can't find $f in src\n";
 }
 
 if ($ret) {
-    print "ERROR: found $ret error(s)\n";
+    print "diff.pl ERROR: found $ret error(s)\n";
 }
 
 exit $ret;
@@ -119,11 +123,11 @@ sub compare
     foreach my $k (keys %$h1) {
         if (!exists $h2->{$k}) {
             $ret++;
-            print "E: Can't find $k for dest $f2 ($k=$h1->{$k})\n";
+            print "diff.pl ERROR: Can't find $k for dest $f2 ($k=$h1->{$k})\n";
         }
         if (!defined $h2->{$k}) {
             $ret++;
-            print "E: $k not found in destination ", $h1->{file}, "\n";
+            print "diff.pl ERROR: $k not found in destination ", $h1->{file}, "\n";
             print Data::Dumper::Dumper($h1, $h2);
         } elsif ($h2->{$k} ne $h1->{$k}) {
             $ret++;
@@ -132,20 +136,23 @@ sub compare
                 ($val1, $val2) = 
                     (map { strftime('%F %T', localtime($_)) } ($val1, $val2));
             }
-            print "E: src and dst $f2 differ on $k ($val1 != $val2)\n";
+            print "diff.pl ERROR: src and dst $f2 differ on $k ($val1 != $val2)\n";
         }
         delete $attr{$k};
     }
 
     foreach my $k (keys %attr) {
         $ret++;
-        print "E: Found $k on dst file and not on src ($k=$h2->{$k})\n";
+        print "diff.pl ERROR: Found $k on dst file and not on src ($k=$h2->{$k})\n";
     }
 }
 
 sub wanted_src
 {
     my $f = $_;
+    if (grep ($f, @exclude)) {
+        return;
+    }
     if (-l $f) {
         my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
             $atime,$mtime,$ctime,$blksize,$blocks) = lstat($f);
@@ -178,35 +185,52 @@ sub wanted_src
             file => $File::Find::name,
         };
         $md5->reset;
-        open(FILE, '<', $f) or die "Can't open '$f': $!";
+        open(FILE, '<', $f) or die "ERROR: Can't open '$f': $!";
         binmode(FILE);
         $hash->{$File::Find::name}->{md5} = $md5->addfile(*FILE)->hexdigest;
         close(FILE);
         
-        if ($acl) {
-            $hash->{$File::Find::name}->{acl} = `getfacl "$f" 2>/dev/null`;
-        }
-        if ($attr) {
-            $hash->{$File::Find::name}->{attr} = `getfattr "$f" 2>/dev/null`;
-        }
-        
     } elsif (-d $f) {
         $hash->{$File::Find::name} = {
             mode => $mode,
             uid => $uid,
             gid => $gid,
-            mtime => $mtime,
+            mtime => ($mtimedir)?$mtime:0,
             type => 'd',
             file =>  $File::Find::name,
         };
-        if ($acl) {
-            $hash->{$File::Find::name}->{acl} = `getfacl "$f" 2>/dev/null`;
-        }
-        if ($attr) {
-            $hash->{$File::Find::name}->{attr} = `getfattr "$f" 2>/dev/null`;
-        }
+
+    } elsif (-b $f or -c $f) { # dev
+        $hash->{$File::Find::name} = {
+            mode => $mode,
+            uid => $uid,
+            gid => $gid,
+            mtime => $mtime,
+            rdev => $rdev,
+            type => (-b $f)?'block':'char',
+            file =>  $File::Find::name,
+        };
+        
+    } elsif (-p $f) { # named pipe
+        $hash->{$File::Find::name} = {
+            mode => $mode,
+            uid => $uid,
+            gid => $gid,
+            mtime => $mtime,
+            type => 'pipe',
+            file =>  $File::Find::name,
+        };
         
     } else {                # other than file and directory
-            
+        return;
+    }
+    
+    my $fe = $f;
+    $fe =~ s/"/\\"/g;
+    if ($acl) {
+        $hash->{$File::Find::name}->{acl} = `getfacl "$fe" 2>/dev/null`;
+    }
+    if ($attr) {
+        $hash->{$File::Find::name}->{attr} = `getfattr "$fe" 2>/dev/null`;
     }
 }