global-functions: $MkDir: create a tmpfs (RAM disk)...

... if the path starts with "tmpfs/". This helps to mitigate flash wear.
This commit is contained in:
Christian Hesse 2022-12-13 15:42:45 +01:00
parent 1579330864
commit 16bfe4de7e

View file

@ -525,6 +525,7 @@
:global CleanFilePath;
:global GetRandom20CharAlNum;
:global LogPrintExit2;
:global RequiredRouterOS;
:global WaitForFile;
:set Path [ $CleanFilePath $Path ];
@ -547,6 +548,15 @@
:set Continue true;
}
:if ($Continue = false && $PathNext = "tmpfs" && [ $RequiredRouterOS $0 "7.7rc1" false ] = true) do={
:if ([ :len [ /disk/find where slot=tmpfs type=tmpfs ] ] = 0) do={
$LogPrintExit2 info $0 ("Creating disk of type tmpfs.") false;
/file/remove [ find where name="tmpfs" type="directory" ];
[ :parse "/disk/add slot=tmpfs type=tmpfs;" ];
}
:set Continue true;
}
:if ($Continue = false && [ :len [ /file/find where name=$PathNext ] ] = 1) do={
$LogPrintExit2 warning $0 ("The path '" . $PathNext . "' exists, but is not a directory.") false;
:return false;