Updated Convert->bytes_to_human_readable() to accept already human-readable sizes and return that.

This resolves issue #282.

Signed-off-by: digimer <digimer@gravitar.alteeve.com>
main
digimer 2 years ago
parent a3988cc3e5
commit 383a6df7c5
  1. 19
      Anvil/Tools/Convert.pm

@ -238,9 +238,26 @@ sub bytes_to_human_readable
# Die if either the 'time' or 'float' has a non-digit character in it. # Die if either the 'time' or 'float' has a non-digit character in it.
if ($human_readable_size =~ /\D/) if ($human_readable_size =~ /\D/)
{ {
# See if this is already human readable.
my $bytes = $anvil->Convert->human_readable_to_bytes({
debug => $debug,
size => $human_readable_size,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'bytes' => $bytes }});
if ($bytes =~ /^\d+$/)
{
# This is fine, convert to our standard size and return.
my $new_human_readable_size = $anvil->Convert->bytes_to_human_readable({
debug => 2,
'bytes' => $bytes,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_human_readable_size => $new_human_readable_size }});
return($new_human_readable_size);
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0116", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0116", variables => {
method => "Convert->bytes_to_human_readable()", method => "Convert->bytes_to_human_readable()",
parameter => "hostnmae", parameter => "bytes",
value => $human_readable_size, value => $human_readable_size,
}}); }});
return ("!!error!!"); return ("!!error!!");

Loading…
Cancel
Save