Compare commits

...

3 commits

Author SHA1 Message Date
Christian Hesse
6680f52012 Merge branch 'file' into next 2025-06-22 00:35:34 +02:00
Christian Hesse
44f7417b7f 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.
2025-06-22 00:15:17 +02:00
Christian Hesse
b3dc8eb92a global-functions: $WaitForFile: (mostly) revert changes
This (mostly) reverts commits 0e00a228d6
and e08bb2192d.

This is required for RouterOS 7.20beta4. It fixed recursive find for
files, and (still, or again?) suffers timing issues getting file
properties.
2025-06-22 00:02:51 +02:00

View file

@ -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 ];
@ -1771,14 +1777,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;
}