Skip to content

Commit

Permalink
automataCI: finalized tar.gz and tar.xz libraries
Browse files Browse the repository at this point in the history
Since we want to release soon, we must finalize the library. Hence,
let's deal with tar.gz and tar.xz libraries.

This patch finalizes tar.gz and tar.xz libraries capabilities in
automataCI/ directory.

Co-authored-by: Galyna, Cory <[email protected]>
Co-authored-by: (Holloway) Chew, Kean Ho <[email protected]>
Signed-off-by: (Holloway) Chew, Kean Ho <[email protected]>
  • Loading branch information
hollowaykeanho and corygalyna committed Dec 15, 2023
1 parent b69d55b commit 09176c5
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 83 deletions.
4 changes: 2 additions & 2 deletions automataCI/_package-archive_unix-any.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PACKAGE::run_archive() {


OS::print_status info "checking tar functions availability...\n"
TAR::is_available
TAR_Is_Available
if [ $? -ne 0 ]; then
OS::print_status error "check failed.\n"
return 1
Expand Down Expand Up @@ -121,7 +121,7 @@ PACKAGE::run_archive() {
*)
_target_path="${_target_path}.tar.xz"
OS::print_status info "packaging ${_target_path}\n"
TAR::create_xz "$_target_path" "*"
TAR_Create_XZ "$_target_path" "*"
__exit=$?
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions automataCI/_package-homebrew_unix-any.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PACKAGE::run_homebrew() {

# validate input
I18N_Status_Print_Check_Availability "TAR"
TAR::is_available
TAR_Is_Available
if [ $? -ne 0 ]; then
I18N_Status_Print_Check_Availability_Incompatible "TAR"
return 1
Expand Down Expand Up @@ -117,7 +117,7 @@ PACKAGE::run_homebrew() {
# archive the assembled payload
__current_path="$PWD" && cd "$_src"
I18N_Status_Print_File_Archive "${_target_path}.tar.xz"
TAR::create_xz "${_target_path}.tar.xz" "*"
TAR_Create_XZ "${_target_path}.tar.xz" "*"
__exit=$?
cd "$__current_path" && unset __current_path
if [ $__exit -ne 0 ]; then
Expand Down
117 changes: 74 additions & 43 deletions automataCI/services/archive/tar.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,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.
. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\io\os.ps1"
. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\compress\gz.ps1"
. "${env:PROJECT_PATH_ROOT}\${env:PROJECT_PATH_AUTOMATA}\services\compress\xz.ps1"
. "${env:LIBS_AUTOMATACI}\services\io\os.ps1"
. "${env:LIBS_AUTOMATACI}\services\io\fs.ps1"
. "${env:LIBS_AUTOMATACI}\services\io\strings.ps1"
. "${env:LIBS_AUTOMATACI}\services\compress\gz.ps1"
. "${env:LIBS_AUTOMATACI}\services\compress\xz.ps1"




function TAR-Is-Available {
# validate input
$__process = Get-Command "tar" -ErrorAction SilentlyContinue
if (-not ($__process)) {
$___process = OS-Is-Command-Available "tar"
if ($___process -ne 0) {
return 1
}

Expand All @@ -33,40 +35,50 @@ function TAR-Is-Available {

function TAR-Create {
param (
[string]$__destination,
[string]$__source,
[string]$__owner,
[string]$__group
[string]$___destination,
[string]$___source,
[string]$___owner,
[string]$___group
)


# validate input
if ([string]::IsNullOrEmpty($__destination) -or [string]::IsNullOrEmpty($__source)) {
if (($(STRINGS-Is-Empty "${___destination}") -eq 0) -or
($(STRINGS-Is-Empty "${___source}") -eq 0)) {
return 1
}

if (Test-Path -Path $__destination) {
$___process = FS-Is-File "${___destination}"
if ($___process -eq 0) {
return 1
}

$__process = TAR-Is-Available
if ($__process -ne 0) {
$___process = FS-Is-Directory "${___destination}"
if ($___process -eq 0) {
return 1
}

$___process = TAR-Is-Available
if ($___process -ne 0) {
return 1
}


# create tar archive
if ((-not [string]::IsNullOrEmpty($__owner)) -and [string]::IsNullOrEmpty($__group)) {
$__arguments = "--numeric-owner --group=`"${__group}`" " `
+ "--owner=`"${__owner}`" " `
+ "-cvf `"${__destination}`" ${__source}"
$__process = OS-Exec "tar" "${__arguments}"
if ($__process -ne 0) {
$___supported = $false # windows' TAR system does not support UNIX UGID system
if (($___supported) -and
($(STRINGS-Is-Empty "${___owner}") -ne 0) -and
($(STRINGS-Is-Empty "${___group}") -ne 0)) {
$___arguments = "--numeric-owner --group=`"${___group}`" " `
+ "--owner=`"${___owner}`" " `
+ "-cvf `"${___destination}`" ${___source}"
$___process = OS-Exec "tar" "${___arguments}"
if ($___process -ne 0) {
return 1
}
} else {
$__process = OS-Exec "tar" "-cvf `"${__destination}`" ${__source}"
if ($__process -ne 0) {
$___process = OS-Exec "tar" "-cvf `"${___destination}`" ${___source}"
if ($___process -ne 0) {
return 1
}
}
Expand All @@ -81,32 +93,39 @@ function TAR-Create {

function TAR-Create-GZ {
param (
[string]$__destination,
[string]$__source,
[string]$__owner,
[string]$__group
[string]$___destination,
[string]$___source,
[string]$___owner,
[string]$___group
)


# validate input
if ([string]::IsNullOrEmpty($__destination) -or [string]::IsNullOrEmpty($__source)) {
if (($(STRINGS-Is-Empty "${___destination}") -eq 0) -or
($(STRINGS-Is-Empty "${___source}") -eq 0)) {
return 1
}

if (Test-Path -Path $__destination) {
$___process = FS-Is-File "${___destination}"
if ($___process -eq 0) {
return 1
}

$___process = FS-Is-Directory "${___destination}"
if ($___process -eq 0) {
return 1
}


# create tar archive
$__dest = $__destination -replace '\.gz.*$'
$__process = TAR-Create "${__dest}" "${__source}" "0" "0"
if ($__process -ne 0) {
$___dest = $___destination -replace '\.gz.*$'
$___process = TAR-Create "${___dest}" "${___source}" "${___owner}" "${___group}"
if ($___process -ne 0) {
return 1
}

$__process = GZ-Create "${__dest}"
if ($__process -ne 0) {
$___process = GZ-Create "${___dest}"
if ($___process -ne 0) {
return 1
}

Expand All @@ -120,19 +139,31 @@ function TAR-Create-GZ {

function TAR-Create-XZ {
param (
[string]$__destination,
[string]$__source,
[string]$__owner,
[string]$__group
[string]$___destination,
[string]$___source,
[string]$___owner,
[string]$___group
)


# validate input
if ([string]::IsNullOrEmpty($__destination) -or [string]::IsNullOrEmpty($__source)) {
if (($(STRINGS-Is-Empty "${___destination}") -eq 0) -or
($(STRINGS-Is-Empty "${___source}") -eq 0)) {
return 1
}

if (Test-Path -Path $__destination) {
$___process = FS-Is-File "${___destination}"
if ($___process -eq 0) {
return 1
}

$___process = FS-Is-Directory "${___destination}"
if ($___process -eq 0) {
return 1
}

$___process = XZ-Is-Available
if ($___process -ne 0) {
return 1
}

Expand All @@ -142,14 +173,14 @@ function TAR-Create-XZ {
}

# create tar archive
$__dest = $__destination -replace '\.xz.*$'
$__process = TAR-Create "${__dest}" "${__source}" "0" "0"
if ($__process -ne 0) {
$___destination = $___destination -replace '\.xz.*$'
$___process = TAR-Create "${___destination}" "${___source}" "${___owner}" "${___group}"
if ($___process -ne 0) {
return 1
}

$__process = XZ-Create "${__dest}"
if ($__process -ne 0) {
$___process = XZ-Create "${___destination}"
if ($___process -ne 0) {
return 1
}

Expand Down
85 changes: 56 additions & 29 deletions automataCI/services/archive/tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +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.
. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/compress/gz.sh"
. "${PROJECT_PATH_ROOT}/${PROJECT_PATH_AUTOMATA}/services/compress/xz.sh"
. "${LIBS_AUTOMATACI}/services/io/os.sh"
. "${LIBS_AUTOMATACI}/services/io/fs.sh"
. "${LIBS_AUTOMATACI}/services/io/strings.sh"
. "${LIBS_AUTOMATACI}/services/compress/gz.sh"
. "${LIBS_AUTOMATACI}/services/compress/xz.sh"




TAR::is_available() {
TAR_Is_Available() {
# execute
if [ -z "$(type -t tar)" ]; then
OS::is_command_available "tar"
if [ $? -ne 0 ]; then
return 1
fi

Expand All @@ -30,30 +34,36 @@ TAR::is_available() {



TAR::create() {
#__destination="$1"
#__source="$2"
#__owner="$3"
#__group="$4"
TAR_Create() {
#___destination="$1"
#___source="$2"
#___owner="$3"
#___group="$4"


# validate input
if [ -z "$2" ] || [ -z "$1" ]; then
if [ $(STRINGS_Is_Empty "$2") -eq 0 ] || [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then
return 1
fi

FS::is_file "$1"
if [ $? -eq 0 ]; then
return 1
fi

if [ -e "$1" ]; then
FS::is_directory "$1"
if [ $? -eq 0 ]; then
return 1
fi

TAR::is_available
TAR_Is_Available
if [ $? -ne 0 ]; then
return 1
fi


# create tar archive
if [ ! -z "$3" -a ! -z "$4" ]; then
if [ $(STRINGS_Is_Empty "$3") -ne 0 ] && [ $(STRINGS_Is_Empty "$4") -ne 0 ]; then
tar --numeric-owner --group="$4" --owner="$3" -cvf "$1" $2
if [ $? -ne 0 ]; then
return 1
Expand All @@ -73,25 +83,31 @@ TAR::create() {



TAR::create_gz() {
#__destination="$1"
#__source="$2"
#__owner="$3"
#__group="$4"
TAR_Create_GZ() {
#___destination="$1"
#___source="$2"
#___owner="$3"
#___group="$4"


# validate input
if [ -z "$2" ] || [ -z "$1" ]; then
if [ $(STRINGS_Is_Empty "$2") -eq 0 ] || [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then
return 1
fi

if [ -e "$1" ]; then
FS::is_file "$1"
if [ $? -eq 0 ]; then
return 1
fi

FS::is_directory "$1"
if [ $? -eq 0 ]; then
return 1
fi


# create tar archive
TAR::create "${1%.gz*}" "$2" "$3" "$4"
TAR_Create "${1%.gz*}" "$2" "$3" "$4"
if [ $? -ne 0 ]; then
return 1
fi
Expand All @@ -111,19 +127,30 @@ TAR::create_gz() {



TAR::create_xz() {
#__destination="$1"
#__source="$2"
#__owner="$3"
#__group="$4"
TAR_Create_XZ() {
#___destination="$1"
#___source="$2"
#___owner="$3"
#___group="$4"


# validate input
if [ -z "$2" ] || [ -z "$1" ]; then
if [ $(STRINGS_Is_Empty "$2") -eq 0 ] || [ $(STRINGS_Is_Empty "$1") -eq 0 ]; then
return 1
fi

if [ -e "$1" ]; then
FS::is_file "$1"
if [ $? -eq 0 ]; then
return 1
fi

FS::is_directory "$1"
if [ $? -eq 0 ]; then
return 1
fi

XZ_Is_Available
if [ $? -ne 0 ]; then
return 1
fi

Expand All @@ -133,7 +160,7 @@ TAR::create_xz() {
fi

# create tar archive
TAR::create "${1%.xz*}" "$2" "$3" "$4"
TAR_Create "${1%.xz*}" "$2" "$3" "$4"
if [ $? -ne 0 ]; then
return 1
fi
Expand Down
Loading

0 comments on commit 09176c5

Please sign in to comment.