From 8c0ff09401178a59df28f128cccd8458ed66afb5 Mon Sep 17 00:00:00 2001 From: mgutt <10757176+mgutt@users.noreply.github.com> Date: Sun, 26 Oct 2025 14:00:57 +0100 Subject: [PATCH] Improve code readability: Reorder progress parsing logic and fix comment (ETA vs elapsed time) --- emhttp/plugins/dynamix/nchan/file_manager | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/emhttp/plugins/dynamix/nchan/file_manager b/emhttp/plugins/dynamix/nchan/file_manager index 82658c2de..e1fd9bc0a 100755 --- a/emhttp/plugins/dynamix/nchan/file_manager +++ b/emhttp/plugins/dynamix/nchan/file_manager @@ -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; }