From d8e1034202bf45e138cf1311074ac019d1814f71 Mon Sep 17 00:00:00 2001 From: mgutt <10757176+mgutt@users.noreply.github.com> Date: Tue, 28 Oct 2025 00:14:43 +0100 Subject: [PATCH] Small rsync ETA fix and improved regex - tac --before prevents line concatenation, when status file randomly lacks trailing \n - Add leading space (^ ) to regex which guarantess matching the progress line --- emhttp/plugins/dynamix/nchan/file_manager | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/emhttp/plugins/dynamix/nchan/file_manager b/emhttp/plugins/dynamix/nchan/file_manager index 64f64947f..813de3380 100755 --- a/emhttp/plugins/dynamix/nchan/file_manager +++ b/emhttp/plugins/dynamix/nchan/file_manager @@ -139,7 +139,9 @@ function parse_rsync_progress($status, $action_label) { // 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 - $progress_line = trim(exec("tac $status | grep -m1 -E '[0-9]+%.*[0-9]+:[0-9]+:[0-9]+' | tr -s ' ' || echo ''")); + // note: leading space in regex ensures we only match progress lines, not filenames + // note: tac --before prevents line concatenation when $status lacks trailing \n + $progress_line = trim(exec("tac --before $status | grep -m1 -E '^ .*[0-9]+%.*[0-9]+:[0-9]+:[0-9]+' | tr -s ' ' || echo ''")); if ($progress_line) { $parts = explode(' ', $progress_line); if (count($parts) >= 4) { @@ -165,7 +167,7 @@ function parse_rsync_progress($status, $action_label) { // obtain filename line like: // "/mnt/disk6/images/image.jpg" // note: -v is used to obtain the opposite of the progress line regex and to filter out empty lines - $file_line = exec("tac $status | grep -m1 -v -E '(^\$|[0-9]+%.*[0-9]+:[0-9]+:[0-9]+)' | tr -s ' ' || echo ''"); + $file_line = exec("tail -n5 $status | grep -v -E '(^\$|^ .*[0-9]+%.*[0-9]+:[0-9]+:[0-9]+)' | tail -1 | tr -s ' ' || echo ''"); if ($file_line) { $text[0] .= htmlspecialchars(mb_strimhalf($file_line, 70, '...'), ENT_QUOTES, 'UTF-8'); }