CSE/Command/Check.pm

filter: Statementstmt 46.4% 26 / 56 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 44.0% 33 / 75 CC 7 SCAR 28.1
CC
7
Cov
41%
execute
27.7
_scrape_lucy_class
2.0
BEGIN
1.0
CRAP 16.6
« CSE/Lucy/Search/QueryPrefix.pm ↑ Summary CSE/Command/Unwatch.pm »
1 package App::CSE::Command::Check;
2 1 $App::CSE::Command::Check::VERSION = '0.016';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 extends qw/App::CSE::Command/;
5  
6 1 ▶use Lucy::Search::IndexSearcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # To check for shared-mime-info DB.
9 1 ▶use File::BaseDir qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 1 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 my $LOGGER = Log::Log4perl->get_logger();
14  
15 1 ▶sub execute{
Subroutine execute: called CC=7 SCAR=33.2
Pod undocumented
16 1 my ($self) = @_;
17  
18 1 my $index_dir = $self->cse()->index_dir();
19  
20 1 ▶ unless( -d $index_dir ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $index_dir) 0 1 1
21 0 $LOGGER->warn("No index $index_dir. You should run 'cse index'");
22 0 return 1;
23 }
24  
25 # The directory is there. Check it is a valid lucy index.
26 1 my $lucy = eval{ my $l = Lucy::Search::IndexSearcher->new( index => $index_dir );
27 0 $l->get_reader();
28 0 $l->get_schema();
29 0 $l;
30 };
31 1 ▶ unless( $lucy ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($lucy) 1 0 1
32 1 my $err = $@;
33 1 $LOGGER->error($self->cse->colorizer->colored("The index $index_dir is not a valid lucy index.", 'red bold'));
34 1 $LOGGER->debug("Lucy error: $err");
35 1 return 1;
36 }
37  
38 0 my $dirty_str = '';
39 0 my $dirty_hash = $self->cse()->dirty_files();
40 0 ▶ if( my $ndirty = scalar( keys %$dirty_hash ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $ndirty = scalar keys %$dirty_hash) 0 0 0
41 0 $dirty_str = ' '.$ndirty.' dirty files - run cse update to clean them';
42 }
43  
44 0 $LOGGER->info("Index $index_dir is healthy.".$dirty_str);
45 0 my $schema = $lucy->get_schema();
46 0 my @fields = sort @{ $schema->all_fields() };
47 0 $LOGGER->info("Fields: ".join(', ', map{ $_.' ('._scrape_lucy_class($schema->fetch_type($_)).')' } @fields));
48 0 $LOGGER->info($lucy->get_reader()->doc_count().' files indexed on '.$self->cse->index_mtime()->iso8601());
49  
50 0 ▶ unless( File::BaseDir::data_files('mime/globs') ){
Branch: 1 branch
BranchTrueFalseTotal
unless (File::BaseDir::data_files("mime/globs")) 0 0 0
51 0 $LOGGER->warn($self->cse->colorizer->colored(q|No mime type info database (mime-info) on the machine.
52  
53 All the files will be considered to be application/octet-stream at index time, making the search useless.
54  
55 The shared-mime-info package is available from http://freedesktop.org/
56  
57 On linux:
58 Check your package manager
59  
60 On OSX:
61 brew install shared-mime-info
62  
63 |, 'yellow bold'));
64 0 return 1;
65 }
66  
67 # Check some watcher.
68 0 ▶ if( my $watcher_pid = $self->cse->index_meta()->{'watcher.pid'} ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $watcher_pid = $self->cse->index_meta->{"watcher.pid"}) 0 0 0
69 0 $LOGGER->info("Dir watcher PID=".$watcher_pid);
70 0 ( $watcher_pid ) = ( $watcher_pid =~ /(\d+)/ );
71 0 ▶ if( kill(0 , $watcher_pid ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (kill 0, $watcher_pid) { } 0 0 0
72 0 $LOGGER->info("Watcher is Running");
73 }else{
74 0 $LOGGER->warn("Looks like watcher PID=$watcher_pid is defunct. Try cse unwatch to clean it up");
75 }
76 }
77  
78  
79 0 return 0;
80 }
81  
82 0 ▶sub _scrape_lucy_class{
Subroutine _scrape_lucy_class: not called CC=1 SCAR=6.9
83 0 my ($o) = @_;
84 0 my $ref = ref($o);
85 0 $ref =~ s/Lucy::Plan:://;
86 0 return $ref;
87 }
88  
89 1 __PACKAGE__->meta->make_immutable();
90  
91 =head1 NAME
92  
93 App::CSE::Command::Check - Checks and display info about an index.
94  
95 =cut
« CSE/Lucy/Search/QueryPrefix.pm ↑ Summary CSE/Command/Unwatch.pm »