From 9524eae48a58a6e567898a7b3d3721c1c6874648 Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Fri, 15 Dec 2023 11:46:44 +0800 Subject: [PATCH] automataCI: finalized zip library Since we want to release soon, we must finalize the library. Hence, let's deal with .zip library. This patch finalizes zip library capabiltiies in automataCI/ directory. Co-authored-by: Galyna, Cory <124406765+corygalyna@users.noreply.github.com> Co-authored-by: (Holloway) Chew, Kean Ho Signed-off-by: (Holloway) Chew, Kean Ho --- automataCI/_package-archive_unix-any.sh | 4 +-- automataCI/_package-chocolatey_unix-any.sh | 2 +- automataCI/services/archive/zip.ps1 | 7 +++-- automataCI/services/archive/zip.sh | 33 +++++++++++--------- automataCI/services/publishers/chocolatey.sh | 4 +-- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/automataCI/_package-archive_unix-any.sh b/automataCI/_package-archive_unix-any.sh index 6d625293..d11944cc 100644 --- a/automataCI/_package-archive_unix-any.sh +++ b/automataCI/_package-archive_unix-any.sh @@ -57,7 +57,7 @@ PACKAGE::run_archive() { fi OS::print_status info "checking zip functions availability...\n" - ZIP::is_available + ZIP_Is_Available if [ $? -ne 0 ]; then OS::print_status error "check failed.\n" return 1 @@ -115,7 +115,7 @@ PACKAGE::run_archive() { windows) _target_path="${_target_path}.zip" OS::print_status info "packaging ${_target_path}\n" - ZIP::create "$_target_path" "*" + ZIP_Create "$_target_path" "*" __exit=$? ;; *) diff --git a/automataCI/_package-chocolatey_unix-any.sh b/automataCI/_package-chocolatey_unix-any.sh index 6513d43f..130e5cdf 100644 --- a/automataCI/_package-chocolatey_unix-any.sh +++ b/automataCI/_package-chocolatey_unix-any.sh @@ -57,7 +57,7 @@ PACKAGE_Run_Chocolatey() { # validate input I18N_Status_Print_Check_Availability "ZIP" - ZIP::is_available + ZIP_Is_Available if [ $? -ne 0 ]; then I18N_Status_Print_Check_Availability_Incompatible "ZIP" return 1 diff --git a/automataCI/services/archive/zip.ps1 b/automataCI/services/archive/zip.ps1 index 42d7cd05..bb188e43 100644 --- a/automataCI/services/archive/zip.ps1 +++ b/automataCI/services/archive/zip.ps1 @@ -23,8 +23,9 @@ function ZIP-Create { # execute try { - Compress-Archive -Path $___source -DestinationPath $___destination - if (Test-Path $___destination) { + $null = Compress-Archive -Path $___source -DestinationPath $___destination + $___process = FS-Is-File "${___destination}" + if ($___process -eq 0) { return 0 } } catch { @@ -61,7 +62,7 @@ function ZIP-Extract { # execute try { $null = FS-Make-Directory "${___destination}" - Expand-Archive -Path $___source -DestinationPath $___destination + $null = Expand-Archive -Path $___source -DestinationPath $___destination } catch { return 1 } diff --git a/automataCI/services/archive/zip.sh b/automataCI/services/archive/zip.sh index ad069230..89f04ea3 100644 --- a/automataCI/services/archive/zip.sh +++ b/automataCI/services/archive/zip.sh @@ -10,18 +10,19 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. +. "${LIBS_AUTOMATACI}/services/io/os.sh" . "${LIBS_AUTOMATACI}/services/io/fs.sh" -ZIP::create() { - # __destination="$1" - # __source="$2" +ZIP_Create() { + #___destination="$1" + #___source="$2" # validate input - ZIP::is_available + ZIP_Is_Available if [ $? -ne 0 ]; then return 1 fi @@ -29,14 +30,13 @@ ZIP::create() { # execute zip -9 -r "$1" $2 + if [ $? -ne 0 ]; then + return 1 + fi # report status - if [ $? -eq 0 ]; then - return 0 - fi - - return 1 + return 0 } @@ -48,15 +48,18 @@ ZIP_Extract() { # validate input - if [ -z "$(type -t unzip)" ]; then + OS::is_command_available "unzip" + if [ $? -ne 0 ]; then return 1 fi - if [ ! -f "$___source" ]; then + FS::is_file "$___source" + if [ $? -ne 0 ]; then return 1 fi - if [ -f "$___destination" ]; then + FS::is_file "$___destination" + if [ $? -eq 0 ]; then return 1 fi @@ -76,12 +79,14 @@ ZIP_Extract() { -ZIP::is_available() { +ZIP_Is_Available() { # execute - if [ ! -z "$(type -t zip)" ]; then + OS::is_command_available "zip" + if [ $? -eq 0 ]; then return 0 fi + # report status return 1 } diff --git a/automataCI/services/publishers/chocolatey.sh b/automataCI/services/publishers/chocolatey.sh index 98d54041..010a9880 100644 --- a/automataCI/services/publishers/chocolatey.sh +++ b/automataCI/services/publishers/chocolatey.sh @@ -75,7 +75,7 @@ CHOCOLATEY_Archive() { return 1 fi - ZIP::is_available + ZIP_Is_Available if [ $? -ne 0 ]; then return 1 fi @@ -83,7 +83,7 @@ CHOCOLATEY_Archive() { # execute ___current_path="$PWD" && cd "$2" - ZIP::create "$1" "*" + ZIP_Create "$1" "*" ___process=$? cd "$___current_path" && unset ___current_path if [ $___process -ne 0 ]; then