aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2022-12-13 15:30:24 +0100
committerGravatar Christian Hesse <mail@eworm.de>2022-12-13 21:25:07 +0100
commit1579330864c98f4526cf5e0f0ea7204ad25f87a3 (patch)
treea8fcdf5143f3040879d41fd3f981f1f84dbf4b95
parent58f769ac0016025533248aba5cd63436b00fc3db (diff)
global-functions: $MkDir: create directories recursively
-rw-r--r--global-functions44
1 files changed, 30 insertions, 14 deletions
diff --git a/global-functions b/global-functions
index f0048dd..9ff6bd5 100644
--- a/global-functions
+++ b/global-functions
@@ -521,6 +521,7 @@
:set MkDir do={
:local Path [ :tostr $1 ];
+ :global CharacterReplace;
:global CleanFilePath;
:global GetRandom20CharAlNum;
:global LogPrintExit2;
@@ -536,22 +537,37 @@
:return true;
}
- :if ([ :len [ /file/find where name=$Path ] ] = 1) do={
- $LogPrintExit2 warning $0 ("The path '" . $Path . "' exists, but is not a directory.") false;
- :return false;
- }
+ :local Error false;
+ :local PathNext "";
+ :foreach Dir in=[ :toarray [ $CharacterReplace $Path "/" "," ] ] do={
+ :local Continue false;
+ :set PathNext [ $CleanFilePath ($PathNext . "/" . $Dir) ];
- :local Return true;
- :local Name ($Path . "-" . [ $GetRandom20CharAlNum 6 ]);
- :do {
- /ip/smb/share/add disabled=yes directory=$Path name=$Name;
- $WaitForFile $Path;
- } on-error={
- $LogPrintExit2 warning $0 ("Making directory '" . $Path . "' failed!") false;
- :set Return false;
+ :if ([ :len [ /file/find where name=$PathNext type="directory" ] ] = 1) do={
+ :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;
+ }
+
+ :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;
+ }
+ }
}
- /ip/smb/share/remove [ find where name=$Name ];
- :return $Return;
+ :return true;
}
# prepare NotificationFunctions array