diff --git a/sbin/prepareWorkspace.sh b/sbin/prepareWorkspace.sh index 6792fe865..886f2c00e 100644 --- a/sbin/prepareWorkspace.sh +++ b/sbin/prepareWorkspace.sh @@ -51,10 +51,11 @@ copyFromDir() { # this is workarounding --strip-components 1 missing on gnu tar # it requires absolute tar-filepath as it changes dir and is hardcoded to one # similar approach can be used also for zip in future -untarGnuAbsPathWithStripComponents1() { +# warning! this method do not merge if (parts of!) destination exists. +unpackGnuAbsPathWithStrip1Component() { local tmp=$(mktemp -d) pushd "$tmp" > /dev/null - tar "$@" + "$@" popd > /dev/null mv "$tmp"/*/* . mv "$tmp"/*/.* . || echo "no hidden files in tarball" @@ -62,18 +63,30 @@ untarGnuAbsPathWithStripComponents1() { rmdir "$tmp" } +untarGnuAbsPathWithStrip1Component() { + unpackGnuAbsPathWithStrip1Component tar -xf "$@" +} + +unzipGnuAbsPathWithStrip1Component() { + unpackGnuAbsPathWithStrip1Component unzip "$@" +} + unpackFromArchive() { echo "Extracting OpenJDK source tarball ${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]} to $(pwd)/${BUILD_CONFIG[OPENJDK_SOURCE_DIR]} to build the binary" # If the tarball contains .git files, they should be ignored later - # todo, support also zips? pushd "./${BUILD_CONFIG[OPENJDK_SOURCE_DIR]}" - local topLevelItems=$(tar --exclude='*/*' -tf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" | grep "/$" -c) || local topLevelItems=1 - if [ "$topLevelItems" -eq "1" ] ; then - echo "Source tarball contains exactly one directory" - untarGnuAbsPathWithStripComponents1 -xf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" + if [ "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]: -4}" == ".zip" ] ; then + echo "Source zip unpacked as if it contains exactly one directory" + unzipGnuAbsPathWithStrip1Component "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" else - echo "Source tarball does not contain a top level directory" - tar -xf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" + local topLevelItems=$(tar --exclude='*/*' -tf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" | grep "/$" -c) || local topLevelItems=1 + if [ "$topLevelItems" -eq "1" ] ; then + echo "Source tarball contains exactly one directory" + untarGnuAbsPathWithStrip1Component "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" + else + echo "Source tarball does not contain a top level directory" + tar -xf "${BUILD_CONFIG[OPENJDK_LOCAL_SOURCE_ARCHIVE_ABSPATH]}" + fi fi rm -rf "build" popd