@@ -29,7 +29,6 @@ use File::Path ();
29
29
use File::Slurp ();
30
30
use IO::Handle ();
31
31
use Fcntl qw( :flock SEEK_END) ;
32
- use Test::More;
33
32
34
33
use FindBin;
35
34
use utf8;
@@ -264,6 +263,7 @@ sub do_search ( $self, %opts ) {
264
263
is_incomplete => $cache -> {is_incomplete } || 0,
265
264
search_in_progress => $cache -> {search_in_progress } || 0,
266
265
match => $cache -> {match },
266
+ adjusted_request => $cache -> {adjusted_request } // {},
267
267
results => $output ,
268
268
time_elapsed => $elapsed ,
269
269
is_a_known_distro => $is_a_known_distro ,
@@ -585,6 +585,23 @@ sub _load_cache ( $self, $cache_file ) {
585
585
return Sereal::read_sereal($cache_file );
586
586
}
587
587
588
+ sub _parse_and_check_query_filetype ( $self , $query_filetype , $adjusted_request ={} ) {
589
+
590
+ my $rules = $self -> _parse_query_filetype($query_filetype );
591
+
592
+ my $r = $rules // [];
593
+ my $value = join ( ' ,' , @$r );
594
+ $query_filetype =~ s {\s +} {} g ;
595
+ if ( $query_filetype ne $value ) {
596
+ $adjusted_request -> {' qft' } = {
597
+ error => " Incorrect search filter: invalid characters - $query_filetype " ,
598
+ value => $value ,
599
+ }
600
+ }
601
+
602
+ return $rules ;
603
+ }
604
+
588
605
sub _parse_query_filetype ( $self , $query_filetype ) {
589
606
590
607
return unless defined $query_filetype ;
@@ -600,6 +617,23 @@ sub _parse_query_filetype ( $self, $query_filetype ) {
600
617
return \@filetypes ;
601
618
}
602
619
620
+ sub _parse_and_check_ignore_files ( $self , $ignore_files , $adjusted_request ={} ) {
621
+
622
+ return unless length $ignore_files ;
623
+
624
+ my $rules = $self -> _parse_ignore_files($ignore_files );
625
+
626
+ if ( ! $rules ) {
627
+ $adjusted_request -> {' qifl' } = {
628
+ error => " Incorrect ignore files: invalid characters." ,
629
+ value => $ignore_files , # not updated
630
+ }
631
+ }
632
+
633
+ return $rules ;
634
+ }
635
+
636
+
603
637
# convert a string of patterns (file to exclude) to a list of git rules to ignore the path
604
638
# t/*, *.md, *.json, *.yaml, *.yml, *.conf, cpanfile, LICENSE, MANIFEST, INSTALL, Changes, Makefile.PL, Build.PL, Copying, *.SKIP, *.ini, README
605
639
sub _parse_ignore_files ( $self , $ignore_files ) {
@@ -652,6 +686,8 @@ sub _get_match_cache(
652
686
return $load if $load ;
653
687
}
654
688
689
+ my $adjusted_request = {};
690
+
655
691
$search_distro =~ s { ::+} { -} g if defined $search_distro ;
656
692
657
693
# the distro can either come from url or the query with some glob
@@ -668,7 +704,7 @@ sub _get_match_cache(
668
704
}
669
705
670
706
# filter on some type files distro + query filetype
671
- if ( my $rules = $self -> _parse_query_filetype ($query_filetype ) ) {
707
+ if ( my $rules = $self -> _parse_and_check_query_filetype ($query_filetype , $adjusted_request ) ) {
672
708
my $base_search = $git_cmd [-1];
673
709
my $is_first_rule = 1;
674
710
foreach my $rule (@$rules ) {
@@ -685,7 +721,7 @@ sub _get_match_cache(
685
721
}
686
722
}
687
723
688
- if ( my $rules = $self -> _parse_ignore_files ($ignore_files ) ) {
724
+ if ( my $rules = $self -> _parse_and_check_ignore_files ($ignore_files , $adjusted_request ) ) {
689
725
push @git_cmd , $rules -> @*;
690
726
}
691
727
@@ -710,8 +746,8 @@ sub _get_match_cache(
710
746
# remove the final marker if there
711
747
my $search_in_progress = 1;
712
748
713
- # note "LAST LINE .... " . $list_files->[-1];
714
- # note " check ? ", $list_files->[-1] eq END_OF_FILE_MARKER() ? 1 : 0;
749
+ # say "LAST LINE .... " . $list_files->[-1];
750
+ # say " check ? ", $list_files->[-1] eq END_OF_FILE_MARKER() ? 1 : 0;
715
751
if ( scalar @$list_files && $list_files -> [-1] eq END_OF_FILE_MARKER() ) {
716
752
pop @$list_files ;
717
753
$search_in_progress = 0;
@@ -744,10 +780,11 @@ sub _get_match_cache(
744
780
files => $match_files ,
745
781
distros => scalar keys $cache -> {distros }-> %*,
746
782
};
783
+ $cache -> {adjusted_request } = $adjusted_request ;
747
784
748
785
if ( !$search_in_progress ) {
749
786
750
- # note "Search in progress..... done caching yaml file";
787
+ # say "Search in progress..... done caching yaml file";
751
788
$self -> _save_cache( $request_cache_file , $cache );
752
789
$self -> _save_cache( $cache_file , $cache );
753
790
unlink $raw_cache_file if -e $raw_cache_file ;
@@ -794,7 +831,7 @@ sub run_git_cmd_limit ( $self, %opts ) {
794
831
}
795
832
else {
796
833
# return the content of our current cache from previous run
797
- # note "use our cache from previous run";
834
+ # say "use our cache from previous run";
798
835
my @from_cache = File::Slurp::read_file($cache_file );
799
836
chomp @from_cache ;
800
837
return \@from_cache ;
@@ -829,7 +866,7 @@ sub run_git_cmd_limit ( $self, %opts ) {
829
866
push @lines , $line ;
830
867
last if ++$c > $limit ;
831
868
832
- # note "GOT: $line ", $line eq END_OF_FILE_MARKER() ? 1 : 0;
869
+ # say "GOT: $line ", $line eq END_OF_FILE_MARKER() ? 1 : 0;
833
870
last if $line eq END_OF_FILE_MARKER();
834
871
}
835
872
alarm(0);
@@ -892,8 +929,8 @@ sub run_git_cmd_limit ( $self, %opts ) {
892
929
exit 42;
893
930
}
894
931
895
- note " Running in kid command: " . join ( ' ' , ' git' , @$cmd );
896
- note " KID is caching to file " , $cache_file ;
932
+ say " Running in kid command: " . join ( ' ' , ' git' , @$cmd );
933
+ say " KID is caching to file " , $cache_file ;
897
934
898
935
my $to_cache ;
899
936
@@ -921,7 +958,7 @@ sub run_git_cmd_limit ( $self, %opts ) {
921
958
qq{ \n } ; # in case of the last line did not had a newline
922
959
print {$to_cache } END_OF_FILE_MARKER() . qq{ \n } if $cache_file ;
923
960
print {$CW } END_OF_FILE_MARKER() . qq{ \n } if $can_write_to_pipe ;
924
- note " -- Request finished by kid: $counter lines - "
961
+ say " -- Request finished by kid: $counter lines - "
925
962
. join ( ' ' , ' git' , @$cmd );
926
963
exit $? ;
927
964
}
0 commit comments