@@ -25,6 +25,7 @@ use Simple::Accessor qw{
25
25
use POSIX qw{ :sys_wait_h setsid} ;
26
26
use Proc::ProcessTable ();
27
27
use Time::HiRes ();
28
+ use File::Path ();
28
29
use File::Slurp ();
29
30
use IO::Handle ();
30
31
use Fcntl qw( :flock SEEK_END) ;
@@ -95,22 +96,20 @@ sub _build_cpan_index_at($self) {
95
96
chomp $out ;
96
97
$out =~ s { ['"]} {} g ;
97
98
98
- return $out ; # . ' ' . $self->HEAD;
99
+ return $out ;
99
100
}
100
101
101
102
sub _build_cache ($self ) {
102
103
103
- # also use HEAD ?? FIXME
104
104
my $dir
105
- = ( $self -> config()-> {' cache' }-> {' directory' } ) . ' /'
106
- . ( $self -> config()-> {' cache' }-> {' version' } || 0 )
107
- . ' /HEAD-'
108
- . $self -> HEAD;
109
- die unless $dir ;
105
+ = $self -> _current_cache_version_directory() . ' /HEAD-' . $self -> HEAD;
110
106
111
107
$dir = $self -> massage_path($dir );
112
- local $ENV {PATH } = ' /bin:' . ( $ENV {PATH } // ' ' );
113
- qx{ mkdir -p $dir } ;
108
+
109
+ return $dir if -d $dir ;
110
+
111
+ File::Path::make_path( $dir , { mode => 0711, } )
112
+ or die " Failed to create $dir : $! " ;
114
113
die unless -d $dir ;
115
114
116
115
# cleanup after directory structure creation
@@ -119,6 +118,12 @@ sub _build_cache($self) {
119
118
return $dir ;
120
119
}
121
120
121
+ sub _current_cache_version_directory ($self ) {
122
+
123
+ return ( $self -> config()-> {' cache' }-> {' directory' } ) . ' /'
124
+ . ( $self -> config()-> {' cache' }-> {' version' } || 0 );
125
+ }
126
+
122
127
sub _build_root ($self ) {
123
128
124
129
# hard code root dir in production
@@ -133,11 +138,9 @@ sub cache_cleanup( $self, $current_cachedir = undef ) { # aka tmpwatch
133
138
134
139
my @path = split qr { /} , $current_cachedir ;
135
140
136
- { # purge old cache versions
137
- my @tmp = @path ;
138
- pop @tmp for 1 .. 2;
141
+ if ( my $cache_root = $self -> config()-> {' cache' }-> {' directory' } ) {
139
142
140
- my $cache_root = join ' / ' , @tmp ;
143
+ # purge old cache versions
141
144
if ( opendir ( my $tmp_dh , $cache_root ) ) {
142
145
foreach my $dir ( readdir ($tmp_dh ) ) {
143
146
next if $dir eq ' .' || $dir eq ' ..' ;
@@ -149,18 +152,16 @@ sub cache_cleanup( $self, $current_cachedir = undef ) { # aka tmpwatch
149
152
next unless -d $fdir ;
150
153
next unless length $fdir > 5;
151
154
152
- local $ENV { PATH } = ' /bin: ' . ( $ENV { PATH } // ' ' );
153
- qx{ rm -rf $fdir }
154
- ; # kind of dangerous but should be ok, we are controlling these values
155
+ # kind of dangerous but should be ok, we are controlling these values
156
+ File::Path::remove_tree( $fdir , { safe => 1 } )
157
+ or warn " Failed to remove $fdir : $! " ;
155
158
}
156
- close ($tmp_dh );
157
159
}
158
160
}
159
161
160
- { # purge old HEAD directories for the same version
161
- my @tmp = @path ;
162
- pop @tmp ;
163
- my $version_cache = join ' /' , @tmp ;
162
+ if ( my $version_cache = $self -> _current_cache_version_directory() ) {
163
+
164
+ # purge old HEAD directories for the same version
164
165
if ( opendir ( my $tmp_dh , $version_cache ) ) {
165
166
foreach my $dir ( readdir ($tmp_dh ) ) {
166
167
next if $dir eq ' .' || $dir eq ' ..' ;
@@ -169,8 +170,9 @@ sub cache_cleanup( $self, $current_cachedir = undef ) { # aka tmpwatch
169
170
next unless -d $fdir ;
170
171
next if $fdir eq $current_cachedir ;
171
172
172
- local $ENV {PATH } = ' /bin:' . ( $ENV {PATH } // ' ' );
173
- qx{ rm -rf $fdir } ; # purge old cache, in the same weird fashion
173
+ # purge old cache, in the same weird fashion
174
+ File::Path::remove_tree( $fdir , { safe => 1 } )
175
+ or warn " Failed to remove $fdir : $! " ;
174
176
}
175
177
}
176
178
}
@@ -180,7 +182,7 @@ sub cache_cleanup( $self, $current_cachedir = undef ) { # aka tmpwatch
180
182
181
183
sub massage_path ( $self , $s ) {
182
184
183
- return unless defined $s ;
185
+ return unless length $s ;
184
186
185
187
my $appdir = $self -> root;
186
188
$appdir =~ s { /(?:bin|t)/?$} {} ;
@@ -560,11 +562,11 @@ sub _save_cache ( $self, $cache_file, $cache ) {
560
562
561
563
sub _get_cache_file ( $self , $keys , $type = undef ) {
562
564
563
- $type //= q[ / search-ls] ;
565
+ $type //= q[ search-ls] ;
564
566
$type .= ' -' ;
565
567
566
568
my $cache_file
567
- = ( $self -> cache() // ' ' )
569
+ = ( $self -> cache() // ' ' ) . ' / '
568
570
. $type
569
571
. md5_hex( join ( q{ |} , map { defined $_ ? $_ : ' ' } @$keys ) )
570
572
. ' .cache' ;
@@ -615,11 +617,6 @@ sub _get_match_cache(
615
617
616
618
$caseinsensitive //= 0;
617
619
618
- my @keys_for_cache = (
619
- $search , $search_distro , $query_filetype ,
620
- $caseinsensitive , $ignore_files // ' '
621
- );
622
-
623
620
my $gitdir = $self -> git()-> work_tree;
624
621
my $limit = $self -> config()-> {limit }-> {files_per_search } or die ;
625
622
@@ -628,6 +625,12 @@ sub _get_match_cache(
628
625
push @git_cmd , q{ -i} if $caseinsensitive ;
629
626
push @git_cmd , $flavor , ' -e' , $search , q{ --} , q{ distros/} ;
630
627
628
+ my @keys_for_cache = (
629
+ $flavor , $caseinsensitive ? 1 : 0,
630
+ $search , $search_distro , $query_filetype ,
631
+ $caseinsensitive , $ignore_files // ' '
632
+ );
633
+
631
634
# use the full cache when available -- need to filter it later
632
635
my $request_cache_file = $self -> _get_cache_file( \@keys_for_cache );
633
636
if ( my $load = $self -> _load_cache($request_cache_file ) ) {
0 commit comments