/usr/bin/plsense-worker-find is in plsense 0.3.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use strict;
use warnings;
use Getopt::Long qw{:config posix_default no_ignore_case gnu_compat};
use IO::Socket;
use Try::Tiny;
use PlSense::Logger;
use PlSense::Configure;
use PlSense::SocketClient;
use PlSense::Util;
use PlSense::ModuleKeeper;
use PlSense::Symbol::Module;
my ($cachedir, $port1, $port2, $port3, $confpath, $is_project, $tasknm, $loglvl, $logfile, @dirs);
GetOptions ('cachedir=s' => \$cachedir,
'port1=i' => \$port1,
'port2=i' => \$port2,
'port3=i' => \$port3,
'confpath=s' => \$confpath,
'project' => \$is_project,
'tasknm=s' => \$tasknm,
'rootdir=s' => \@dirs,
'loglevel=s' => \$loglvl,
'logfile=s' => \$logfile, );
setup_logger($loglvl, $logfile);
if ( ! -d $cachedir ) {
logger->crit("Not exist cache directory [$cachedir]");
exit 1;
}
set_primary_config( cachedir => $cachedir,
port1 => $port1,
port2 => $port2,
port3 => $port3,
loglevel => $loglvl,
logfile => $logfile, );
setup_config($confpath) or exit 1;
set_mdlkeeper( PlSense::ModuleKeeper->new() );
my $scli = PlSense::SocketClient->new({ retryinterval => 0.5, maxretry => 200 });
my $projectnm = get_config("name");
my $nowstoringmdl = undef;
my (@mdl_or_files, @needbuild, @firstbuild, %found_is, %lastmodified_of);
$SIG{INT} = sub { logger->notice("Receive SIGINT"); resume_store(); exit 0; };
$SIG{TERM} = sub { logger->notice("Receive SIGTERM"); resume_store(); exit 0; };
mdlkeeper->setup_without_reload();
LIBPATH:
foreach my $dir ( @dirs ) {
chomp $dir;
if ( ! $dir || ! -d $dir ) {
logger->error("Not given or not exist directory : $dir");
next LIBPATH;
}
$dir = File::Spec->rel2abs($dir);
logger->debug("Start find module in [$dir]");
LINE:
foreach my $line ( qx{ find "$dir" -follow -name '*.pm' -type f -print0 | xargs -0 egrep -H -o '^package\\s+[a-zA-Z0-9_:]+\\s*;' } ) {
if ( $line !~ m{ \A ( .. [^:]* \.pm ) : package \s+ ([a-zA-Z0-9:]+) \s* ; }xms ) { next LINE; }
my ($filepath, $mdlnm) = ($1, $2);
try {
my $lastmodified = $lastmodified_of{$filepath};
if ( ! $lastmodified ) {
my @attr = stat $filepath;
$lastmodified = $attr[9];
$lastmodified_of{$filepath} = $lastmodified;
}
MDL:
foreach my $mdlnm ( "main", $mdlnm ) {
my $mdl = $is_project ? mdlkeeper->get_project_module($mdlnm, $filepath)
: mdlkeeper->get_module($mdlnm, $filepath);
if ( ! $mdl ) {
logger->info("Found not yet stored module [$mdlnm] in [$filepath]");
$mdl = PlSense::Symbol::Module->new({ name => $mdlnm,
filepath => $filepath,
projectnm => $is_project ? $projectnm : "",
lastmodified => $lastmodified });
logger->notice("New module [".$mdl->get_name."] in [".$mdl->get_filepath."] belong [".$mdl->get_projectnm."]");
$nowstoringmdl = $mdl;
mdlkeeper->store_module($mdl);
$nowstoringmdl = undef;
if ( $is_project ) {
my $mdlkey = $mdl->get_name eq "main" ? $mdl->get_filepath : $mdl->get_name;
push @firstbuild, $mdlkey;
}
}
my $mdlkey = $mdl->get_name eq "main" ? $mdl->get_filepath : $mdl->get_name;
if ( $found_is{$mdlkey} ) { next MDL; }
$found_is{$mdlkey} = 1;
if ( $mdl->get_name ne "main" ) { push @mdl_or_files, $mdlkey; }
# The not yet built module don't need to be built in find process.
my $needbuild = $mdl->is_initialized;
if ( $lastmodified != $mdl->get_lastmodified && $mdl->get_filepath eq $filepath && $needbuild ) {
push @needbuild, $mdlkey;
}
elsif ( $mdl->get_filepath ne $filepath && $mdl->get_projectnm eq $projectnm ) {
logger->info("Found moved module [$mdlnm] from [".$mdl->get_filepath."] to [$filepath]");
$mdl = PlSense::Symbol::Module->new({ name => $mdlnm,
filepath => $filepath,
projectnm => $is_project ? $projectnm : "",
lastmodified => $lastmodified });
logger->notice("New module [".$mdl->get_name."] in [".$mdl->get_filepath."] belong [".$mdl->get_projectnm."]");
$nowstoringmdl = $mdl;
mdlkeeper->store_module($mdl);
$nowstoringmdl = undef;
if ( $needbuild ) { push @needbuild, $mdlkey; }
}
}
}
catch {
my $e = shift;
logger->error("Failed find module from line : $e");
};
}
logger->notice("Finished find modules in $dir");
}
if ( $#mdl_or_files >= 0 ) {
$is_project ? $scli->request_main_server("foundp ".join("|", @mdl_or_files))
: $scli->request_main_server("found ".join("|", @mdl_or_files));
}
if ( $#needbuild >= 0 ) {
logger->notice("Request build updated/moved modules : ".join(", ", @needbuild));
$scli->request_work_server("buildrf ".join("|", @needbuild));
}
if ( $#firstbuild >= 0 ) {
logger->notice("Request build project modules : ".join(", ", @firstbuild));
$scli->request_work_server("buildr ".join("|", @firstbuild));
}
$scli->request_work_server("finfind $tasknm");
exit 0;
sub resume_store {
my $mdl = $nowstoringmdl;
if ( $mdl && $mdl->isa("PlSense::Symbol::Module") ) {
mdlkeeper->store_module($mdl);
$nowstoringmdl = undef;
}
}
|