#!/usr/bin/perl

use Getopt::Std;

getopts("dmx:h");

$s=shift;
$d=shift;
die <<'EOF'
Need two directories to compare, and maybe
   -d             ignore dir-mtime
   -m             expect mismatch in directory listing
   -x <pattern>   ignore changes that match this pattern
EOF
if $opt_h || !($s && $d);


# find /tmp/fsvs-test-1000/wc-1/ -printf "% y%04m %7s %5G %5U %T+ %P\0\t%l\0\n"
# strace -o /tmp/asdga -f -tt 
$cmd=qq'LANG=C rsync -ain --delete "$s" "$d" -c';
@changes=();
for (`$cmd`)
{
# Ignore empty lines.
  next if m(^\s*$);

# ignore root directory
  next if m(\.d......... \./\s*$);

# ignore mtime of links
  next if m(\.L\.\.t\.\.\.\.\.\. .* -> );
# and directories
  next if $opt_d && m(\.d\.\.t\.\.\.\.\.\. .*);

  next if $opt_x && m($opt_x)o;

# everything else is a change.
  push @changes, $_;
#.L..t...... typechange/device-symlink -> device-1
#>fc........ typechange/dir-file
#.L..t...... typechange/file-symlink -> file-1
#cL+++++++++ typechange/symlink-symlink -> symlink-1
}

$SIG{"__DIE__"} = sub { print STDERR '$ ',$cmd,"\n",@changes,@_; exit 1; };

if ($opt_m && @changes)
{
  print "----- expected differences\n";
# pass output for further processing
  print @changes;
  exit 0;
}

die "----- Differences were found\n" if @changes;

print "----- comparison of directory gave no differences\n";
exit 0;

