aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-03-29 12:13:59 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-03-29 12:13:59 +0200
commit814fb7197fcd4587c97e1699c356c7e96df5a95c (patch)
tree0b9ecc78158c0266dd6198a5577a226061ad8784 /global-functions.rsc
parentd700dbc00e6e22ea9521d3b359f0d3635d9af682 (diff)
parentf2e811527206373d91ffa36f4a9662b1adb563d2 (diff)
Merge branch 'mkdir' into next
Diffstat (limited to 'global-functions.rsc')
-rw-r--r--global-functions.rsc98
1 files changed, 64 insertions, 34 deletions
diff --git a/global-functions.rsc b/global-functions.rsc
index 2249fe9..24b6223 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -561,6 +561,26 @@
:global RequiredRouterOS;
:global WaitForFile;
+ :local MkTmpfs do={
+ :global LogPrintExit2;
+ :global WaitForFile;
+
+ :if ([ :len [ /disk/find where slot=tmpfs type=tmpfs ] ] = 1) do={
+ :return true;
+ }
+
+ $LogPrintExit2 info $0 ("Creating disk of type tmpfs.") false;
+ /file/remove [ find where name="tmpfs" type="directory" ];
+ :do {
+ /disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3);
+ $WaitForFile "tmpfs";
+ } on-error={
+ $LogPrintExit2 warning $0 ("Creating disk of type tmpfs failed!") false;
+ :return false;
+ }
+ :return true;
+ }
+
:set Path [ $CleanFilePath $Path ];
:if ($Path = "") do={
@@ -571,49 +591,59 @@
:return true;
}
- :local Error false;
- :local PathNext "";
- :foreach Dir in=[ :toarray [ $CharacterReplace $Path "/" "," ] ] do={
- :local Continue false;
- :set PathNext [ $CleanFilePath ($PathNext . "/" . $Dir) ];
-
- :if ([ :len [ /file/find where name=$PathNext !(name="tmpfs") type="directory" ] ] = 1) do={
- :set Continue true;
- }
-
- :if ($Continue = false && $PathNext = "tmpfs") 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" ];
- :do {
- /disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3);
- $WaitForFile "tmpfs";
- } on-error={
- $LogPrintExit2 warning $0 ("Creating disk of type tmpfs failed!") false;
- :set Error true;
- }
+ :if ([ $RequiredRouterOS $0 "7.9beta4" false ] = true) do={
+ :if ([ :pick $Path 0 5 ] = "tmpfs") do={
+ :if ([ $MkTmpfs ] = false) do={
+ :return false;
}
- :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;
+ :do {
+ :local File ($Path . "/file");
+ /file/add name=$File;
+ $WaitForFile $File;
+ /file/remove $File;
+ } on-error={
+ $LogPrintExit2 warning $0 ("Making directory '" . $Path . "' failed!") false;
:return false;
}
+ } else={
+ :local Error false;
+ :local PathNext "";
+ :foreach Dir in=[ :toarray [ $CharacterReplace $Path "/" "," ] ] do={
+ :local Continue false;
+ :set PathNext [ $CleanFilePath ($PathNext . "/" . $Dir) ];
+
+ :if ([ :len [ /file/find where name=$PathNext !(name="tmpfs") type="directory" ] ] = 1) do={
+ :set Continue true;
+ }
- :if ($Continue = false) do={
- :local Name ($PathNext . "-" . [ $GetRandom20CharAlNum 6 ]);
- :do {
- /ip/smb/share/add disabled=yes directory=$PathNext name=$Name;
- $WaitForFile $PathNext;
- } on-error={
- $LogPrintExit2 warning $0 ("Making directory '" . $PathNext . "' failed!") false;
- :set Error true;
+ :if ($Continue = false && $PathNext = "tmpfs") do={
+ :if ([ $MkTmpfs ] = false) do={
+ :return false;
+ }
+ :set Continue true;
}
- /ip/smb/share/remove [ find where name=$Name ];
- :if ($Error = true) do={
+
+ :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;
}
+
+ :if ($Continue = false) do={
+ :local Name ($PathNext . "-" . [ $GetRandom20CharAlNum 6 ]);
+ :do {
+ /ip/smb/share/add disabled=yes directory=$PathNext name=$Name;
+ $WaitForFile $PathNext;
+ } on-error={
+ $LogPrintExit2 warning $0 ("Making directory '" . $PathNext . "' failed!") false;
+ :set Error true;
+ }
+ /ip/smb/share/remove [ find where name=$Name ];
+ :if ($Error = true) do={
+ :return false;
+ }
+ }
}
}
:return true;