From c361caee5b1996f0d7c6cc44c159f21b3f801e95 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 13 Feb 2019 09:44:15 +0100 Subject: global-functions: introduce and use $CleanFilePath --- global-functions | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index d55d0a6..f1d9ba2 100644 --- a/global-functions +++ b/global-functions @@ -137,6 +137,25 @@ } } +# clean file path +:global CleanFilePath do={ + :local Path [ :tostr $1 ]; + + :global CharacterReplace; + + :while ($Path ~ "//") do={ + :set $Path [ $CharacterReplace $Path "//" "/" ]; + } + :if ([ :pick $Path 0 ] = "/") do={ + :set Path [ :pick $Path 1 [ :len $Path ] ]; + } + :if ([ :pick $Path ([ :len $Path ] - 1) ] = "/") do={ + :set Path [ :pick $Path 0 ([ :len $Path ] - 1) ]; + } + + :return $Path; +} + # download package from upgrade server :global DownloadPackage do={ :local PkgName [ :tostr $1 ]; @@ -145,16 +164,14 @@ :local PkgDir [ :tostr $4 ]; :global CertificateAvailable; + :global CleanFilePath; :if ([ :len $PkgName ] = 0) do={ return false; } :if ([ :len $PkgVer ] = 0) do={ :set PkgVer [ / system package update get installed-version ]; } :if ([ :len $PkgArch ] = 0) do={ :set PkgArch [ / system resource get architecture-name ]; } :local PkgFile ($PkgName . "-" . $PkgVer . "-" . $PkgArch . ".npk"); - :local PkgDest $PkgFile; - :if ($PkgDir != "") do={ - :set PkgDest ($PkgDir . "/" . $PkgFile); - } + :local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ]; $CertificateAvailable "Let's Encrypt Authority X3" "letsencrypt"; :do { -- cgit v1.2.3-70-g09d2