]> git.sur5r.net Git - bacula/bacula/commitdiff
regress: diff.pl - check mtime on directories with --mtime-dir, add support for pipe...
authorEric Bollengier <eric@eb.homelinux.org>
Wed, 23 Jun 2010 12:49:58 +0000 (14:49 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Mon, 2 Aug 2010 14:53:56 +0000 (16:53 +0200)
Depending on the restore order, a directory could be restored before a
file inside it. The resulting mtime could be wrong.

Add support for special files like named pipe, char and block special devices.

regress/scripts/diff.pl

index 013632443374448cd78d3d607b1b9ca49d3c9943..a90e6a19013c208361614ee9d4d9b91f322dc9e9 100755 (executable)
@@ -21,17 +21,19 @@ 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 $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
            "help"    => \$help,
     ) or pod2usage(-verbose => 1, 
                    -exitval => 1);
@@ -146,6 +148,7 @@ sub compare
 sub wanted_src
 {
     my $f = $_;
+
     if (-l $f) {
         my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
             $atime,$mtime,$ctime,$blksize,$blocks) = lstat($f);
@@ -183,30 +186,47 @@ sub wanted_src
         $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`;
     }
 }