diff -r 4668386ec082 -r 0bef3b8087c1 CrashTest.pl --- a/CrashTest.pl Mon May 28 00:23:21 2012 +0200 +++ b/CrashTest.pl Mon May 28 00:24:07 2012 +0200 @@ -4,10 +4,12 @@ use UUID; use Mojo::JSON; use Mojo::UserAgent; +use lib 'lib'; +use CrashTest::Storage::FileSystem; my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; my $config = plugin 'Config'; -my $data_path = $config->{DataDir}; +my $storage = CrashTest::Storage::FileSystem->new($config->{DataDir}); helper scm_file_link => sub { @@ -22,7 +24,8 @@ my $scmrepo = "$scm:$repo"; if(exists($config->{ScmLinks}->{$scmrepo})) { return Mojo::ByteStream->new($self->link_to("$filename:$line" => - $self->render(inline => $config->{ScmLinks}->{$scmrepo}, repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1) + $self->render(inline => $config->{ScmLinks}->{$scmrepo}, + repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1) )); } #return $file; @@ -53,47 +56,13 @@ # Upload form in DATA section get '/' => sub { my $self = shift; - - my @files; - opendir my ($dh), $data_path or die $!; - my @allfiles = readdir $dh; - foreach(@allfiles) - { - if($_ =~ /(.*)\.json$/) - { - my $filename = File::Spec->catfile($data_path, $_); - push @files, { - file => $filename, - uuid => $1, - signature => $1, - product => "", - date => (stat $filename)[9], - }; - } - } - closedir $dh; - - my @sorted_files = ( sort { $b->{date} <=> $a->{date} } @files ); - @sorted_files = @sorted_files[0..19] if scalar(@sorted_files) > 20; - - $self->stash(files => \@sorted_files); - + $self->stash(files => $storage->index()); $self->render('index'); } => 'index'; get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub { my $self = shift; - - open JSON, '<', File::Spec->catfile($data_path, $self->param('uuid') . '.json') or die $!; - my @json_content_lines = ; - my $json_content = join('', @json_content_lines); - close JSON; - - my $json = Mojo::JSON->new; - my $processed_data = $json->decode($json_content); - - $self->stash(processed_data => $processed_data); - + $self->stash(processed_data => $storage->get_processed_data($self->param('uuid'))); $self->render('report/crash'); } => 'report'; @@ -105,22 +74,21 @@ my ($uuid, $uuidstr); UUID::generate($uuid); UUID::unparse($uuid, $uuidstr); - my $dmp_file = File::Spec->catfile($data_path, "$uuidstr.dmp"); + my $dmp_file = "/tmp/$uuidstr.dmp"; $file->move_to($dmp_file); - # Create json for the params - my %paramshash = map { $_ => $self->req->param($_) } $self->req->param; - my $out = qx($config->{MinidumpStackwalkJSON} "$dmp_file" $config->{SymbolsPath} 2>/dev/null) or die $!; my $json = Mojo::JSON->new; my $pjson = $json->decode($out); + + # Create json for the params + my %paramshash = map { $_ => $self->req->param($_) } $self->req->param; $pjson->{client_info} = \%paramshash; - my $j = $json->encode($pjson); - open JSON, '>', File::Spec->catfile($data_path, "$uuidstr.json") or die $!; - print JSON $j; - close JSON; + $storage->store_dump($uuidstr, $file); + $storage->store_processed_data($uuidstr, $pjson); + unlink $dmp_file if -w $dmp_file; # reply $self->render_text($pjson->{status});