diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index 2d8bdf6f..c118f2ff 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -1037,7 +1037,7 @@ sub _set_paths usermod => "/usr/sbin/usermod", uuidgen => "/usr/bin/uuidgen", virsh => "/usr/bin/virsh", - wget => "", + wget => "/usr/bin/wget", }, json => { files => "files.json", diff --git a/Anvil/Tools/Convert.pm b/Anvil/Tools/Convert.pm index f795fb41..f1bdf484 100644 --- a/Anvil/Tools/Convert.pm +++ b/Anvil/Tools/Convert.pm @@ -18,7 +18,7 @@ my $THIS_FILE = "Convert.pm"; # hostname_to_ip # human_readable_to_bytes # round - +# time =pod @@ -989,6 +989,10 @@ If set to C<< 1 >>, the long suffixes will be used instead of the default C<< w/ B<< Note >>: The suffixes are translatable in both short (default) and long formats. See the C<< suffix_0002 >> through C<< suffix_0011 >> string keys. +=head3 translate (optional, default '0') + +When set to C<< 1 >>, the string returned will be translated into plain language. When set to C<< 0 >> (the default), the string returned will not have translated words, but instead return the C<< #!string!x!# >> codes for insertion into templates, email bodies or other uses where translation will be done later. + =cut sub time { @@ -997,19 +1001,15 @@ sub time my $anvil = $self->parent; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; - my $time = $parameter->{'time'} ? $parameter->{'time'} : 0; - my $long = $parameter->{long} ? $parameter->{long} : 0; + my $time = $parameter->{'time'} ? $parameter->{'time'} : 0; + my $long = $parameter->{long} ? $parameter->{long} : 0; + my $translate = $parameter->{translate} ? $parameter->{translate} : 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - 'time' => $time, - long => $long, + 'time' => $time, + long => $long, + translate => $translate, }}); - if (not $time) - { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Storage->update_file()", parameter => "time" }}); - return("#!error!#"); - } - # Remote commas and verify we're left with a number. $time =~ s/,//g; if ($time =~ /^\d+\.\d+$/) @@ -1110,8 +1110,14 @@ sub time }}); } - # Return an already-translated string - $say_time = $anvil->Words->string({debug => $debug, string => $say_time}); + # Return an already-translated string, if asked. + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { translate => $translate }}); + if ($translate) + { + $say_time = $anvil->Words->string({debug => $debug, string => $say_time}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { say_time => $say_time }}); + } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { say_time => $say_time }}); return($say_time); } diff --git a/Anvil/Tools/Log.pm b/Anvil/Tools/Log.pm index 6607a524..2e19e791 100644 --- a/Anvil/Tools/Log.pm +++ b/Anvil/Tools/Log.pm @@ -407,7 +407,7 @@ sub entry print $THIS_FILE." ".__LINE__."; HANDLE::log::main: [".$anvil->data->{HANDLE}{'log'}{main}."]\n" if $test; # Make sure it can be written to by apache. - $anvil->Storage->change_mode({test => $test, debug => $debug, target => $log_file, mode => "0666"}); + $anvil->Storage->change_mode({test => $test, debug => $debug, path => $log_file, mode => "0666"}); } if (not $anvil->data->{HANDLE}{'log'}{main}) diff --git a/Anvil/Tools/Storage.pm b/Anvil/Tools/Storage.pm index ce8a9d8d..cc52dea5 100644 --- a/Anvil/Tools/Storage.pm +++ b/Anvil/Tools/Storage.pm @@ -320,13 +320,13 @@ fi"; This changes the mode of a file or directory. - $anvil->Storage->change_mode({target => "/tmp/foo", mode => "0644"}); + $anvil->Storage->change_mode({path => "/tmp/foo", mode => "0644"}); If it fails to write the file, an alert will be logged. Parameters; -=head3 target (required) +=head3 path (required) This is the file or directory to change the mode on. @@ -342,18 +342,18 @@ sub change_mode my $anvil = $self->parent; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; - my $target = defined $parameter->{target} ? $parameter->{target} : ""; - my $mode = defined $parameter->{mode} ? $parameter->{mode} : ""; + my $path = defined $parameter->{path} ? $parameter->{path} : ""; + my $mode = defined $parameter->{mode} ? $parameter->{mode} : ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - target => $target, - mode => $mode, + mode => $mode, + path => $path, }}); my $error = 0; - if (not $target) + if (not $path) { - # No target... - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Storage->change_mode()", parameter => "target" }}); + # No path... + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Storage->change_mode()", parameter => "path" }}); $error = 1; } if (not $mode) @@ -371,7 +371,7 @@ sub change_mode if (not $error) { - my $shell_call = $anvil->data->{path}{exe}{'chmod'}." $mode $target"; + my $shell_call = $anvil->data->{path}{exe}{'chmod'}." $mode $path"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }}); open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); while(<$file_handle>) @@ -390,23 +390,23 @@ sub change_mode This changes the owner and/or group of a file or directory. - $anvil->Storage->change_owner({target => "/tmp/foo", user => "apache", group => "apache" }); + $anvil->Storage->change_owner({path => "/tmp/foo", user => "apache", group => "apache" }); If it fails to write the file, an alert will be logged and 'C<< 1 >>' will be returned. Otherwise, 'C<< 0 >>' will be returned. Parameters; -=head3 target (required) +=head3 path (required) This is the file or directory to change the mode on. =head3 group (optional, default is the main group of the user running the program) -This is the group name or UID to set the target to. +This is the group name or UID to set the path to. =head3 user (optional, default is the user running the program) -This is the user name or UID to set the target to. +This is the user name or UID to set the path to. =cut sub change_owner @@ -416,11 +416,11 @@ sub change_owner my $anvil = $self->parent; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; - my $target = defined $parameter->{target} ? $parameter->{target} : ""; + my $path = defined $parameter->{path} ? $parameter->{path} : ""; my $group = defined $parameter->{group} ? $parameter->{group} : getgrgid($(); my $user = defined $parameter->{user} ? $parameter->{user} : getpwuid($<); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - target => $target, + path => $path, group => $group, user => $user, }}); @@ -435,15 +435,15 @@ sub change_owner my $string = ""; my $error = 0; - if (not $target) + if (not $path) { - # No target... - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Storage->change_owner()", parameter => "target" }}); + # No path... + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Storage->change_owner()", parameter => "path" }}); $error = 1; } - if (not -e $target) + if (not -e $path) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0051", variables => {target => $target }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0051", variables => {path => $path }}); $error = 1; } @@ -464,7 +464,7 @@ sub change_owner $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error, string => $string }}); if ((not $error) && ($string ne "")) { - my $shell_call = $anvil->data->{path}{exe}{'chown'}." $string $target"; + my $shell_call = $anvil->data->{path}{exe}{'chown'}." ".$string." ".$path; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }}); open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); while(<$file_handle>) @@ -1066,12 +1066,12 @@ fi;"; print $THIS_FILE." ".__LINE__."; mode: [".$mode."]\n" if $test; if ($mode) { - $anvil->Storage->change_mode({debug => $debug, target => $working_directory, mode => $mode}); + $anvil->Storage->change_mode({debug => $debug, path => $working_directory, mode => $mode}); } print $THIS_FILE." ".__LINE__."; user: [".$user."], group: [".$group."]\n" if $test; if (($user) or ($group)) { - $anvil->Storage->change_owner({debug => $debug, target => $working_directory, user => $user, group => $group}); + $anvil->Storage->change_owner({debug => $debug, path => $working_directory, user => $user, group => $group}); } if (not -e $working_directory) @@ -2845,7 +2845,7 @@ fi"; if ($secure) { $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{touch}." ".$file}); - $anvil->Storage->change_mode({debug => $debug, target => $file, mode => $mode}); + $anvil->Storage->change_mode({debug => $debug, path => $file, mode => $mode}); } # Now write the file. @@ -2857,11 +2857,11 @@ fi"; if ($mode) { - $anvil->Storage->change_mode({debug => $debug, target => $file, mode => $mode}); + $anvil->Storage->change_mode({debug => $debug, path => $file, mode => $mode}); } if (($user) or ($group)) { - $anvil->Storage->change_owner({debug => $debug, target => $file, user => $user, group => $group}); + $anvil->Storage->change_owner({debug => $debug, path => $file, user => $user, group => $group}); } } } diff --git a/share/words.xml b/share/words.xml index a4f79be4..9b6aa98d 100644 --- a/share/words.xml +++ b/share/words.xml @@ -291,7 +291,7 @@ It also has replacement variables: [#!variable!first!#] and [#!variable!second!# read_variable() was called but both the 'variable_name' and 'variable_uuid' parameters were not passed or both were empty.]]> insert_or_update_variables() method was called but both the 'variable_name' and 'variable_uuid' parameters were not passed or both were empty.]]> - change_mode() was called without an invalid 'mode' parameter. It should have been three or four digits, but: [#!variable!mode!#] was passed.]]> + change_mode() was called without an invalid 'mode' parameter. It should have been three or four digits, or 'x+/-y' format, but: [#!variable!mode!#] was passed.]]> The host: [#!variable!host!#] has released its database lock. write_file() was asked to write the file: [#!variable!file!#] but it already exists and 'overwrite' was not set. Aborting.]]> write_file() was asked to write the file: [#!variable!file!#] but it is not a full path. Aborting.]]> @@ -304,7 +304,7 @@ It also has replacement variables: [#!variable!first!#] and [#!variable!second!# [ Error ] - There is a local database defined, but it does not appear to exist and we could not initialize the database server. Is 'postgresql-server' installed? - change_owner() was asked to change the ownership of: [#!variable!target!#] which doesn't exist.]]> + change_owner() was asked to change the ownership of: [#!variable!path!#] which doesn't exist.]]> #!variable!method!#() was called but the source file: [#!variable!source_file!#] doesn't exist.]]> connect()' method tried to connect to the same database twice: [#!variable!target!#].]]> @@ -602,6 +602,7 @@ We will keep looking. time() was passed the 'time' of: [#!variable!time!#] which does not appear to be a whole number.]]> call() was passed the 'timeout' of: [#!variable!timeout!#] which does not appear to be a whole number.]]> We have a connection open already to: [#!variable!connection!#], skipping connect stage. + The file: [#!variable!file!#] has beed successfully downloaded. Test @@ -878,7 +879,9 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp #!variable!output!# ==== - Failed to backup: [#!variable!file!#], skipping.. + Failed to backup: [#!variable!file!#], skipping. + The file to be downloaded: [#!variable!file!#], already exists. Either remove it, or call again with '--overwrite'. + Something went wrong moving the downloaded file from the temporary location: [#!variable!source_file!#] to the output: [#!variable!target_file!#]. Useful errors may be above this message. Yes diff --git a/tools/anvil-download-file b/tools/anvil-download-file index 1450bf27..fd958ac6 100755 --- a/tools/anvil-download-file +++ b/tools/anvil-download-file @@ -12,6 +12,8 @@ # 5 = The requested URL failed because there is no route to that host. # 6 = Abort requested, but UUID or PID not passed # 7 = The requested URL failed because the network is unreachable. +# 8 = The file to download already exists. +# 9 = Something went wrong moving the file from temp to the output directory. # # # TODO: @@ -43,14 +45,18 @@ $anvil->Log->secure({set => 1}); $anvil->data->{switches}{abort} = ""; $anvil->data->{switches}{'job-uuid'} = ""; +$anvil->data->{switches}{overwrite} = ""; $anvil->data->{switches}{'save-to'} = ""; # /mnt/shared/files by default +$anvil->data->{switches}{script} = ""; $anvil->data->{switches}{url} = ""; $anvil->Get->switches; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - 'switches::abort' => $anvil->data->{switches}{abort}, - 'switches::job-uuid' => $anvil->data->{switches}{'job-uuid'}, - 'switches::save-to' => $anvil->data->{switches}{'save-to'}, - 'switches::url' => $anvil->data->{switches}{url}, + 'switches::abort' => $anvil->data->{switches}{abort}, + 'switches::job-uuid' => $anvil->data->{switches}{'job-uuid'}, + 'switches::overwrite' => $anvil->data->{switches}{overwrite}, + 'switches::save-to' => $anvil->data->{switches}{'save-to'}, + 'switches::script' => $anvil->data->{switches}{script}, + 'switches::url' => $anvil->data->{switches}{url}, }}); @@ -79,22 +85,24 @@ $anvil->nice_exit({exit_code => 0}); # Private functions. # ############################################################################################################# -sub abort_download +sub download_file { my ($anvil) = @_; - my $failed = 0; - my $url = $anvil->data->{switches}{url}; - my $file_name = ($url =~ /^.*\/(.*)$/)[0]; - my $temp_file = $anvil->data->{path}{directories}{shared}{temp}."/".$file; - my $save_to = $anvil->data->{switches}{'save-to'} ? $anvil->data->{switches}{'save-to'} : $anvil->data->{path}{directories}{shared}{files}; - my $out_file = $save_to."/".$file; - $save_to =~ s/\/\///g; + my $failed = 0; + my $url = $anvil->data->{switches}{url}; + my $file_name = ($url =~ /^.*\/(.*)$/)[0]; + my $temp_file = $anvil->data->{path}{directories}{shared}{temp}."/".$file_name; + my $save_to = $anvil->data->{switches}{'save-to'} ? $anvil->data->{switches}{'save-to'} : $anvil->data->{path}{directories}{shared}{files}; + my $out_file = $save_to."/".$file_name; + $save_to =~ s/\/\///g; + my $unix_start = time; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - url => $url, - file_name => $file_name, - temp_file => $temp_file, - save_to => $save_to, + url => $url, + file_name => $file_name, + temp_file => $temp_file, + unix_start => $unix_start, + save_to => $save_to, }}); # Is this a supported protocol? @@ -104,6 +112,37 @@ sub abort_download $anvil->nice_exit({exit_code => 1}); } + # If the target file exists, exit. + if ((-e $out_file) && (not $anvil->data->{switches}{overwrite})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "err", key => "error_0059", variables => { file => $out_file }}); + $anvil->nice_exit({exit_code => 8}); + } + + # Make sure the output directory exists. + if (not -e $save_to) + { + my $failed = $anvil->Storage->make_directory({ + debug => 2, + directory => $save_to, + mode => "0777", + user => "apache", + group => "apache", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }}); + } + if (not -e $anvil->data->{path}{directories}{shared}{temp}) + { + my $failed = $anvil->Storage->make_directory({ + debug => 2, + directory => $anvil->data->{path}{directories}{shared}{temp}, + mode => "0777", + user => "apache", + group => "apache", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }}); + } + ### NOTE: We don't use System->call because we need to track the output in real time. # Try to download it. my $bytes_downloaded = 0; @@ -112,12 +151,19 @@ sub abort_download my $rate = 0; # Bytes/sec my $time_left = 0; # Seconds my $running_time = 0; + my $average_rate = 0; + my $report_interval = 5; # Seconds between status file update + my $next_report = time + $report_interval; my $shell_call = $anvil->data->{path}{exe}{wget}." --continue --progress=dot:binary ".$url." --output-document ".$temp_file; - open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + next_report => $next_report, + shell_call => $shell_call, + }}); + open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); while(<$file_handle>) { chomp; - my $line = $anvil->Words->clean_spaces({ string => $_ });; + my $line = $anvil->Words->clean_spaces({string => $_});; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0017", variables => { line => $line }}); # Check for problems @@ -162,12 +208,22 @@ sub abort_download ### NOTE: According to: http://savannah.gnu.org/bugs/index.php?22765, wget uses base-2. # Convert $bytes_downloaded = $downloaded * 1024; - my $say_downloaded = $anvil->Convert->bytes_to_human_readable({'bytes' => $bytes_downloaded}); + my $say_downloaded = $anvil->Convert->bytes_to_human_readable({debug => 3, 'bytes' => $bytes_downloaded}); my $say_percent = $percent."%"; - my $byte_rate = $anvil->Convert->human_readable_to_bytes({size => $rate, base2 => 1}); - my $say_rate = $anvil->Convert->bytes_to_human_readable({'bytes' => $byte_rate})."/s"; + my $byte_rate = $anvil->Convert->human_readable_to_bytes({debug => 3, size => $rate, base2 => 1}); + my $say_rate = $anvil->Convert->bytes_to_human_readable({debug => 3, 'bytes' => $byte_rate})."/s"; $running_time = time - $unix_start; - my $say_running_time = $an->Readable->time({'time' => $running_time, process => 1}); + my $say_running_time = $anvil->Convert->time({debug => 3, 'time' => $running_time, translate => 1}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + bytes_downloaded => $bytes_downloaded, + say_downloaded => $say_downloaded, + say_percent => $say_percent, + byte_rate => $byte_rate, + say_rate => $say_rate, + running_time => $running_time, + say_running_time => $say_running_time, + }}); + # Time left is a bit more complicated my $days = 0; my $hours = 0; @@ -176,55 +232,111 @@ sub abort_download if ($time_left =~ /(\d+)d/) { $days = $1; - #print "$THIS_FILE ".__LINE__."; == days: [$days]\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { days => $days }}); } if ($time_left =~ /(\d+)h/) { $hours = $1; - #print "$THIS_FILE ".__LINE__."; == hours: [$hours]\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { hours => $hours }}); } if ($time_left =~ /(\d+)m/) { $minutes = $1; - #print "$THIS_FILE ".__LINE__."; == minutes: [$minutes]\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { minutes => $minutes }}); } if ($time_left =~ /(\d+)s/) { $seconds = $1; - #print "$THIS_FILE ".__LINE__."; == seconds: [$seconds]\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { seconds => $seconds }}); } my $seconds_left = (($days * 86400) + ($hours * 3600) + ($minutes * 60) + $seconds); - my $say_time_left = $an->Readable->time({'time' => $seconds_left, suffix => "long", process => 1}); + my $say_time_left = $anvil->Convert->time({debug => 3, 'time' => $seconds_left, suffix => "long", translate => 1}); $running_time = 1 if not $running_time; $average_rate = int($bytes_downloaded / $running_time); - my $say_average_rate = $anvil->Convert->bytes_to_human_readable({'bytes' => $average_rate})."/s"; + my $say_average_rate = $anvil->Convert->bytes_to_human_readable({debug => 3, 'bytes' => $average_rate})."/s"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + seconds_left => $seconds_left, + say_time_left => $say_time_left, + running_time => $running_time, + average_rate => $average_rate, + say_average_rate => $say_average_rate, + }}); - #print "$THIS_FILE ".__LINE__."; downloaded: [$downloaded], bytes_downloaded: [$bytes_downloaded], say_downloaded: [$say_downloaded], percent: [$percent], rate: [$rate], byte_rate: [$byte_rate], say_rate: [$say_rate], time_left: [$time_left]\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'time' => time, + next_report => $next_report, + }}); if (time > $next_report) { - #print "$THIS_FILE ".__LINE__."; say_downloaded: [$say_downloaded], percent: [$percent], say_rate: [$say_rate], running_time: [$running_time], say_running_time: [$say_running_time], seconds_left: [$seconds_left], say_time_left: [$say_time_left]\n"; - #print "$file; Downloaded: [$say_downloaded]/[$say_percent], Rate/Avg: [$say_rate]/[$say_average_rate], Running: [$say_running_time], Left: [$say_time_left]\n"; - #print "$THIS_FILE ".__LINE__."; bytes_downloaded=$bytes_downloaded, percent=$percent, current_rate=$byte_rate, average_rate=$average_rate, seconds_running=$running_time, seconds_left=$seconds_left, out_file=$out_file\n"; - $next_report += $report_interval; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + say_downloaded => $say_downloaded, + percent => $percent, + say_rate => $say_rate, + running_time => $running_time, + say_running_time => $say_running_time, + seconds_left => $seconds_left, + say_time_left => $say_time_left, + say_percent => $say_percent, + say_average_rate => $say_average_rate, + average_rate => $average_rate, + }}); - my $shell_call = $progress_file; - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "shell_call", value1 => $shell_call, - }, file => $THIS_FILE, line => __LINE__}); - open (my $file_handle, ">$shell_call") or $an->Alert->error({title_key => "an_0003", message_key => "error_title_0015", message_variables => { shell_call => $shell_call, error => $! }, code => 2, file => $THIS_FILE, line => __LINE__}); - print $file_handle "uuid=$uuid bytes_downloaded=$bytes_downloaded percent=$percent current_rate=$byte_rate average_rate=$average_rate seconds_running=$running_time seconds_left=$seconds_left url=$url out_file=$out_file\n"; - close $file_handle; + my $line = "bytes_downloaded=$bytes_downloaded percent=$percent current_rate=$byte_rate average_rate=$average_rate seconds_running=$running_time seconds_left=$seconds_left url=$url out_file=$out_file"; + $next_report += $report_interval; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + line => $line, + next_report => $next_report, + }}); + print $line."\n"; } } } close $file_handle; + # We should have the file now. Move it to the final position. + if (($failed) or (not -e $temp_file)) + { + # Something went wrong. Unlink the temp file. + if (-e $temp_file) + { + unlink $temp_file; + } + $anvil->nice_exit({exit_code => $failed}); + } + else + { + # Move it (overwrite set because we'd be dead by now if '--overwrite' wasn't used. + my $failed = $anvil->Storage->move_file({ + debug => 2, + source_file => $temp_file, + target_file => $save_to, + overwrite => 1, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }}); + if (($failed) or (not -e $out_file)) + { + # Something went wrong. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, priority => "err", key => "error_0060", variables => { + source_file => $temp_file, + target_file => $save_to, + }}); + $anvil->nice_exit({exit_code => 8}); + } + } + + # Set it executable if '--script' was used. + if ($anvil->data->{switches}{script}) + { + $anvil->Storage->change_mode({debug => 2, path => $out_file, mode => "a+x"}); + } + # Tell the user that we're done. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, , key => "log_0297", variables => { file => $out_file }}); return(0); } -sub download_file +sub abort_download { my ($anvil) = @_; diff --git a/tools/anvil-manage-files b/tools/anvil-manage-files index 56839d17..c313edf8 100755 --- a/tools/anvil-manage-files +++ b/tools/anvil-manage-files @@ -834,7 +834,7 @@ sub handle_script { # Switch it on $executable = 1; - $anvil->Storage->change_mode({target => $anvil->data->{switches}{file}, mode => "a+x"}); + $anvil->Storage->change_mode({path => $anvil->data->{switches}{file}, mode => "a+x"}); } else { @@ -848,7 +848,7 @@ sub handle_script { # Switch it off. $executable = 1; - $anvil->Storage->change_mode({target => $anvil->data->{switches}{file}, mode => "a-x"}); + $anvil->Storage->change_mode({path => $anvil->data->{switches}{file}, mode => "a-x"}); } else { diff --git a/tools/striker-manage-install-target b/tools/striker-manage-install-target index be82f4c5..657b3cf1 100755 --- a/tools/striker-manage-install-target +++ b/tools/striker-manage-install-target @@ -601,8 +601,8 @@ sub setup_boot_environment elsif ($kickstart_success eq "1") { # Updated - $anvil->Storage->change_mode({target => $kickstart_file, mode => "0664"}); - $anvil->Storage->change_owner({target => $kickstart_file, user => "apache", group => "apache" }); + $anvil->Storage->change_mode({path => $kickstart_file, mode => "0664"}); + $anvil->Storage->change_owner({path => $kickstart_file, user => "apache", group => "apache" }); print $anvil->Words->string({key => "message_0097", variables => { file => $kickstart_file }})."\n"; update_progress($anvil, $progress, "message_0097,!!file!".$kickstart_file."!!");