From 64158498504635d98adac896f480d71d9bf8a2a9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 21 Jun 2025 23:09:24 +0200 Subject: [PATCH 1/2] global-functions: $WaitForFile: (mostly) revert changes This (mostly) reverts commits 0e00a228d67d77fadc80eee2df04c2cec25b8db8 and e08bb2192dfd22b25652553f28304818a3602331. This is required for RouterOS 7.20beta4. That fixed recursive find for files, and (again, or still?) suffers timing (and thus racing) issues getting file properties. This breaks RouterOS 7.20beta2 again, so that specific version is not supported. Just update... --- global-functions.rsc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 50426b6..fd89f0f 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1771,14 +1771,26 @@ :global MAX; :set FileName [ $CleanFilePath $FileName ]; - :local Delay ([ $MAX [ $EitherOr $WaitTime 2s ] 100ms ] / 10); + :local Delay ([ $MAX [ $EitherOr $WaitTime 2s ] 100ms ] / 9); :do { - :retry { + :retry { + :if ([ :len [ /file/find where name=$FileName ] ] = 0) do={ + :error false; + } + } delay=$Delay max=10; + } on-error={ + :return false; + } + + :while ([ :len [ /file/find where name=$FileName ] ] > 0) do={ + :do { /file/get $FileName; :return true; - } delay=$Delay max=10; - } on-error={ } + } on-error={ } + :delay $Delay; + :set Delay ($Delay * 3 / 2); + } :return false; } From 1307b8587e57deaf95146820b7f32bb9a713892d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 22 Jun 2025 00:15:17 +0200 Subject: [PATCH 2/2] global-functions: $FileGet: mitigate race with file properties RouterOS is suffering a race condition, where a file exists, but its properties are not (yet) available. This is handled in $WaitForFile. This passes an interval of zero to $WaitForFile, as does not wait for the file to exist, but wants to avoid the race only. --- global-functions.rsc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/global-functions.rsc b/global-functions.rsc index fd89f0f..829cbf2 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -559,6 +559,12 @@ :set FileGet do={ :local FileName [ :tostr $1 ]; + :global WaitForFile; + + :if ([ $WaitForFile $FileName 0s ] = false) do={ + :return false; + } + :local FileVal false; :do { :set FileVal [ /file/get $FileName ];