global-functions: $MkDir: abuse smb share to create directory

The smb feature is provided by system package... So we have it anyway.
It gives some benefits compared to abusing fetch:

* It is faster!
* No need to alter, enable and restore a service! (The share is created disabled.)
* Firewall rules can not break this.
* No temporary file is created.
* Less code!

Let's hope we do not introduce new breakage.

Closes #14
This commit is contained in:
Christian Hesse 2021-06-21 21:08:26 +02:00
parent c0b954abbb
commit 7fb4fdfca2

View file

@ -536,6 +536,7 @@
:local Dir [ :tostr $1 ]; :local Dir [ :tostr $1 ];
:global CleanFilePath; :global CleanFilePath;
:global GetRandom20CharHex;
:global WaitForFile; :global WaitForFile;
:set Dir [ $CleanFilePath $Dir ]; :set Dir [ $CleanFilePath $Dir ];
@ -545,17 +546,14 @@
} }
:local Return true; :local Return true;
:local WwwVal [ / ip service get www ]; :local Name ($Dir . "-" . [ $GetRandom20CharHex ])
/ ip service set www address=127.0.0.1/32 disabled=no port=80;
:do { :do {
/ tool fetch http://127.0.0.1/ dst-path=($Dir . "/tmp") as-value; / ip smb share add disabled=yes directory=$Dir name=$Name;
$WaitForFile ($Dir . "/tmp"); $WaitForFile $Dir;
/ file remove ($Dir . "/tmp");
} on-error={ } on-error={
:set Return false; :set Return false;
} }
/ ip service set www address=($WwwVal->"address") \ / ip smb share remove [ find where name=$Name ];
disabled=($WwwVal->"disabled") port=($WwwVal->"port");
:return $Return; :return $Return;
} }