Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better database validation.

Don't delete invalid datbases (rt 16039).
  • Loading branch information...
commit 9fed1571f9df7831c625aaf8fe93ab9969edff00 1 parent 23dd131
@pjcj authored
Showing with 22 additions and 7 deletions.
  1. +6 −1 cover
  2. +16 −6 lib/Devel/Cover/DB.pm
View
7 cover
@@ -83,8 +83,13 @@ sub delete_db
for my $del (@_)
{
print "Deleting database $del\n" unless $Options->{silent};
- next unless -d $del;
my $db = Devel::Cover::DB->new(db => $del);
+ unless ($db->is_valid)
+ {
+ print "Devel::Cover: $del is an invalid database - ignoring\n"
+ unless $Options->{silent};
+ next;
+ }
$db->delete;
rmtree($del);
}
View
22 lib/Devel/Cover/DB.pm
@@ -45,17 +45,13 @@ sub new
$self->{base} ||= $self->{db};
bless $self, $class;
- my $file;
if (defined $self->{db})
{
$self->validate_db;
- $file = "$self->{db}/$DB";
+ my $file = "$self->{db}/$DB";
$self->read($file) if -e $file;
- return $self unless -e $file;
}
- # croak "No input db, filehandle or cover" unless defined $self->{cover};
-
$self
}
@@ -149,13 +145,27 @@ sub validate_db
# is not there but the db directory is empty.
# die if the db is invalid.
+ # just warn for now
+ print "Devel::Cover: $self->{db} is an invalid database\n"
+ unless $self->is_valid;
+
$self
}
sub is_valid
{
my $self = shift;
- -e "$self->{db}/$DB"
+ return 1 if -e "$self->{db}/$DB";
+ opendir my $fh, $self->{db} or return 0;
+ for my $file (readdir $fh)
+ {
+ next if $file eq "." || $file eq "..";
+ next if ($file eq "runs" || $file eq "structure") &&
+ -e "$self->{db}/$file";
+ # warn "found $file in $self->{db}";
+ return 0;
+ }
+ closedir $fh
}
sub collected
Please sign in to comment.
Something went wrong with that request. Please try again.