diff --git a/Anvil/Tools/Words.pm b/Anvil/Tools/Words.pm index b674ae13..3939cdb3 100755 --- a/Anvil/Tools/Words.pm +++ b/Anvil/Tools/Words.pm @@ -250,6 +250,8 @@ sub language This takes a string (usually from a DB record) in the format C<< [,!!var1!value1!!,!!var2!value2!!,...,!!varN!valueN!! >> and converts it into an actual string. +If there is a problem processing the string, C<< !!error!! >> is returned. + Parameters; =head3 key_string (required) @@ -291,31 +293,42 @@ sub parse_banged_string key => $key, variable_string => $variable_string, }}); - foreach my $pair (split/,/, $variable_string) + my $loop = 0; + while ($variable_string) { + my $pair = ($variable_string =~ /^(!!.*?!.*?!!).*$/)[0]; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { pair => $pair }}); - my $name = ""; - my $value = ""; - if ($pair =~ /^!!(.*?)!(.*)!!$/) + + my ($variable, $value) = ($pair =~ /^!!(.*?)!(.*?)!!$/); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + variable => $variable, + value => $value, + }}); + + # Remove this pair + $variable_string =~ s/^$pair//; + $variable_string =~ s/^,//; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_string => $variable_string }}); + + if (not $variable) { - $name = $1; - $value = $2; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - name => $name, - value => $value, - }}); + # Variable missing, nothing we can do with this. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0206", variables => { message => $message }}); } - elsif ($pair =~ /^!!(.*?)!!!$/) + else { - $name = $1; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { name => $name }}); + # Record the variable/value pair + $variables->{$variable} = $value; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "variables->$variable" => $variables->{$variable} }}); } - else + + $loop++; + if ($loop > 10000) { - # what?! + # Stuck in an infinite loop. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0037", variables => { message => $message }}); + return("!!error!!"); } - $variables->{$name} = $value; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "variables->$name" => $variables->{$name} }}); } # Parse the line now. diff --git a/share/words.xml b/share/words.xml index 340136dd..746d9d9f 100644 --- a/share/words.xml +++ b/share/words.xml @@ -92,7 +92,7 @@ Report if a reboot is needed: #!variable!program!# Previous run exited early. Restarting momentarily. No updates were found or needed. - Packages downloaded: [#!variable!downloaded!#], Installed/Updates: [#!variable!installed!#], Verified: [#!variable!verified!#], Output lines: [#!variable!lines!#]. + * Packages downloaded: [#!variable!downloaded!#], Installed or updated: [#!variable!installed!#], Verified: [#!variable!verified!#], Output lines: [#!variable!lines!#]. Starting: [#!variable!program!#]. @@ -333,6 +333,7 @@ The database connection error was: Disconnected from all databases. Will reconnect when entering the main loop. Starting the background process: [#!variable!call!#] now. Background process: [#!variable!call!#] running with PID: [#!variable!pid!#]. + In Words->parse_banged_string(), while processing: [#!variable!message!#], a variable name was found to be missing. Test @@ -529,6 +530,7 @@ The update appears to have not completed successfully. The output was: ==== + In Words->parse_banged_string(), an infinite loop was detected while processing: [#!variable!message!#]. Yes diff --git a/tools/anvil-daemon b/tools/anvil-daemon index 03e402f0..10d268d7 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -59,11 +59,19 @@ if (not $anvil->data->{sys}{database}{connections}) } # Read switches -$anvil->data->{switches}{'run-once'} = ""; -$anvil->data->{switches}{'main-loop-only'} = ""; +$anvil->data->{switches}{'refresh-json'} = ""; +$anvil->data->{switches}{'run-once'} = 0; +$anvil->data->{switches}{'main-loop-only'} = 0; $anvil->data->{switches}{'no-start'} = 0; $anvil->Get->switches; +if ($anvil->data->{switches}{'refresh-json'}) +{ + $anvil->data->{switches}{'run-once'} = 1; + $anvil->data->{switches}{'main-loop-only'} = 1; + $anvil->data->{switches}{'no-start'} = 1; +} + # There are some things we only want to run on (re)start and don't need to always run. run_once($anvil) if not $anvil->data->{switches}{'main-loop-only'}; @@ -335,10 +343,10 @@ sub run_jobs } # Convert the double-banged strings into a proper message. - my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : ""; - my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : ""; - my $say_status = $job_status ? $anvil->Words->parse_banged_string({key_string => $job_status}) : ""; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { + my $say_title = $job_title ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_title}) : ""; + my $say_description = $job_description ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_description}) : ""; + my $say_status = $job_status ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_status}) : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_title => $job_title, say_description => $say_description, say_status => $say_status, @@ -349,7 +357,7 @@ sub run_jobs { my $html_strip = HTML::Strip->new(); $say_status = $html_strip->parse($say_status); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_status => $say_status }}); # Now make the resulting text string HTML friendly my $text_to_html = HTML::FromText->new({ @@ -358,7 +366,7 @@ sub run_jobs lines => 1, }); $say_status = $text_to_html->parse($say_status); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_status => $say_status }}); } # Add this to the jobs.json file diff --git a/tools/anvil-update-system b/tools/anvil-update-system index cda292f6..7e448597 100755 --- a/tools/anvil-update-system +++ b/tools/anvil-update-system @@ -141,6 +141,7 @@ WHERE } # Clea any old runs. +$anvil->data->{sys}{last_update} = time; update_progress($anvil, 0, "clear"); # We'll keep a count of lines and packages to show the user. @@ -150,8 +151,8 @@ $anvil->data->{counts}{verified} = 0; $anvil->data->{counts}{lines} = 0; # Mark that we're starting -update_progress($anvil, 1, "message_0033"); -update_progress($anvil, 2, "message_0058,!!downloaded!0!!,!!installed!0!!,!!verified!0!!,!!lines!0!!"); +update_progress($anvil, 1, "message_0058,!!downloaded!0!!,!!installed!0!!,!!verified!0!!,!!lines!0!!"); +update_progress($anvil, 2, "message_0033"); # Make sure maintenance mode is enabled. $anvil->System->maintenance_mode({debug => 3, set => 1}); @@ -248,13 +249,23 @@ WHERE # Insert counts if ($job_status =~ /message_0058/gs) { - my $downloaded = $anvil->Convert->add_commas({number => $anvil->data->{counts}{downloaded}}); - my $installed = $anvil->Convert->add_commas({number => $anvil->data->{counts}{installed}}); - my $verified = $anvil->Convert->add_commas({number => $anvil->data->{counts}{verified}}); - my $lines = $anvil->Convert->add_commas({number => $anvil->data->{counts}{lines}}); + my $downloaded = $anvil->data->{counts}{downloaded} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{downloaded}}) : 0; + my $installed = $anvil->data->{counts}{installed} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{installed}}) : 0; + my $verified = $anvil->data->{counts}{verified} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{verified}}) : 0; + my $lines = $anvil->data->{counts}{lines} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{lines}}) : 0; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "s1:counts::downloaded" => $anvil->data->{counts}{downloaded}, + "s2:downloaded" => $downloaded, + "s3:counts::installed" => $anvil->data->{counts}{installed}, + "s4:installed" => $installed, + "s5:counts::verified" => $anvil->data->{counts}{verified}, + "s6:verified" => $verified, + "s7:counts::lines" => $anvil->data->{counts}{lines}, + "s8:lines" => $lines, + }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ">> job_status" => $job_status }}); - $job_status =~ s/message_0058,!!downloaded!\d+!!,!!installed!\d+!!,!!verified!\d+!!,!!lines!\d+!!/message_0058,!!downloaded!$downloaded!!,!!installed!$installed!!,!!verified!$verified!!,!!lines!$lines!!/sm; + $job_status =~ s/message_0058,!!downloaded!.*?!!,!!installed!.*?!!,!!verified!.*?!!,!!lines!.*?!!/message_0058,!!downloaded!$downloaded!!,!!installed!$installed!!,!!verified!$verified!!,!!lines!$lines!!/sm; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "<< job_status" => $job_status }}); } @@ -273,6 +284,9 @@ WHERE "; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + + # Note this update time + $anvil->data->{sys}{last_update} = time; } return(0); @@ -416,6 +430,12 @@ sub run_os_update update_progress($anvil, $progress, ""); } } + + # Update the progress if it's been more than a second since the last update. + if (time > $anvil->data->{sys}{last_update}) + { + update_progress($anvil, $progress, ""); + } } close $file_handle;