Archive-Par

 view release on metacpan or  search on metacpan

t/moved.t  view on Meta::CPAN


Tests that the given files are not individually recoverable, allegedly.

(1) miffy.2
(2) miffy.3
(4) miffy.4

=cut

ok $par->file_recoverable('miffy.2');
ok $par->file_recoverable('miffy.3');
ok $par->file_recoverable('miffy.4');

# -------------------------------------

=head2 Test 34--51: Restore File

Attempts to restore from the par file

(1) Check no exception thrown
(2--6) Check that all files are now ok (as per par instance)
(7--18) For each of miffy.{2,3,4}
  (a) Check that file really exists
  (b) Check that file matches that in testref
  (c) Check that miffy-moved.whatever does not exist
  (d) Check that file.bad does not exist

=cut

my $skip = ! -w DATA_DIR;

unless ( $skip ) {
  for (grep ! $skip, map "miffy.$_", 1,3..5) {
    cp catfile(DATA_DIR, $_), $_
      or die sprintf "Failed to move %s -> %s: $!", catfile(DATA_DIR, $_), $_;
  }
}

skip $skip, evcheck(sub { $par->restore(1) }, 'Restore File (1)'),
   1, 'Restore File (1)';

skip $skip, $par->file_ok(sprintf "miffy.%d", $_)
  for (1..5);

for (2..4) {
  my $recover = catfile DATA_DIR, "miffy.$_";
  my $checkfn = catfile REF_DIR,  "miffy.$_";
  my $old1    = catfile DATA_DIR, "miffy-moved.$_";
  my $old2    = catfile DATA_DIR, "miffy.$_.bad";
  skip $skip, -e $recover;
  skip $skip, cmp($recover, $checkfn), 0, sprintf('Restore File (%d)', $_*3+2);
  skip $skip, ! -e $_
    for $old1, $old2;
}

unless ( $skip ) {
  for (2,4) {
    mv catfile(DATA_DIR, "miffy.$_"), catfile(DATA_DIR, "miffy-moved.$_");
  }
  for (map "miffy.$_", 1,3..5) {
    my $stat = (stat($_))[2] & 0777;
    my $target = catfile(DATA_DIR, $_);
    chmod 0600, $target
      if -e $target; # #4 should be gone
    cp $_, $target
      or die sprintf "Failed to move %s -> %s: $!", $_, $target;
    chmod $stat, $target;
  }
}

# -------------------------------------



( run in 2.002 seconds using v1.01-cache-2.11-cpan-98e64b0badf )