mirror of
https://github.com/unraid/webgui.git
synced 2026-01-04 08:29:51 -06:00
Improve code readability: Reorder progress parsing logic and fix comment (ETA vs elapsed time)
This commit is contained in:
@@ -63,17 +63,10 @@ function mb_strimhalf($text, $width, $trim_marker = "") {
|
||||
|
||||
function parse_rsync_progress($status, $action_label) {
|
||||
|
||||
// obtain filename line like "/mnt/disk6/images/image.jpg" (-v is used to obtain the opposite of the progress line regex)
|
||||
$file_line = exec("tac $status | grep -m1 -v -E '[0-9]+%.*[0-9]+:[0-9]+:[0-9]+' | tr -s ' ' || echo ''");
|
||||
$text[0] = $action_label . "... ";
|
||||
if ($file_line) {
|
||||
$text[0] .= htmlspecialchars(mb_strimhalf($file_line, 70, '...'), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
// obtain progress line like:
|
||||
// currently running (showing total ETA):
|
||||
// " 37.91G 4% 58.59MB/s 3:47:20"
|
||||
// transfer of single file finished (ETA changes temporarily to estimated time)
|
||||
// transfer of single file finished (ETA changes temporarily to elapsed time)
|
||||
// " 37.93G 4% 53.80MB/s 0:11:12 (xfr#32, to-chk=554/596)"
|
||||
// note: we do not loop with PHP as there could be a huge amount of progress lines b
|
||||
$progress_line = trim(exec("tac $status | grep -m1 -E '[0-9]+%.*[0-9]+:[0-9]+:[0-9]+' | tr -s ' ' || echo ''"));
|
||||
@@ -84,6 +77,13 @@ function parse_rsync_progress($status, $action_label) {
|
||||
}
|
||||
}
|
||||
|
||||
// obtain filename line like "/mnt/disk6/images/image.jpg" (-v is used to obtain the opposite of the progress line regex)
|
||||
$file_line = exec("tac $status | grep -m1 -v -E '[0-9]+%.*[0-9]+:[0-9]+:[0-9]+' | tr -s ' ' || echo ''");
|
||||
$text[0] = $action_label . "... ";
|
||||
if ($file_line) {
|
||||
$text[0] .= htmlspecialchars(mb_strimhalf($file_line, 70, '...'), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user