From: sgn <sgn@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: Re: [PR PATCH] [Updated] hooks: do-extract: extract to tempdir and rename
Date: Sun, 19 Sep 2021 12:13:20 +0200 [thread overview]
Message-ID: <20210919101320.1QJRq8-gXRYuCG_zZaVdm3AzQR2GPiZF0cs7tS_P5I8@z> (raw)
In-Reply-To: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-33013@inbox.vuxu.org>
[-- Attachment #1: Type: text/plain, Size: 1269 bytes --]
There is an updated pull request by sgn against master on the void-packages repository
https://github.com/sgn/void-packages hooks-do-extract
https://github.com/void-linux/void-packages/pull/33013
hooks: do-extract: extract to tempdir and rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
---
Competing with #33006, the idea is his, anyway.
A patch file from https://github.com/void-linux/void-packages/pull/33013.patch is attached
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-hooks-do-extract-33013.patch --]
[-- Type: text/x-diff, Size: 4722 bytes --]
From ca58ac17d234f3376da13ade7bcd91738d5e295e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sat, 18 Sep 2021 21:02:51 +0700
Subject: [PATCH 1/2] hooks: do-extract: simplify gem extraction
---
| 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
--git a/common/hooks/do-extract/00-distfiles.sh b/common/hooks/do-extract/00-distfiles.sh
index 922f7029491a..ca2011d5c45a 100644
--- a/common/hooks/do-extract/00-distfiles.sh
+++ b/common/hooks/do-extract/00-distfiles.sh
@@ -3,7 +3,7 @@
hook() {
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
- local f j curfile found extractdir
+ local f j curfile found extractdir innerdir
local TAR_CMD
if [ -z "$distfiles" -a -z "$checksum" ]; then
@@ -150,16 +150,10 @@ hook() {
fi
;;
gem)
- case "$TAR_CMD" in
- *bsdtar)
- $TAR_CMD -xOf $srcdir/$curfile data.tar.gz | \
- $TAR_CMD -xz -C "$extractdir" -s ",^,${wrksrc##*/}/," -f -
- ;;
- *)
- $TAR_CMD -xOf $srcdir/$curfile data.tar.gz | \
- $TAR_CMD -xz -C "$extractdir" --transform="s,^,${wrksrc##*/}/,"
- ;;
- esac
+ innerdir="$extractdir/${wrksrc##*/}"
+ mkdir -p "$innerdir"
+ $TAR_CMD -xOf $srcdir/$curfile data.tar.gz |
+ $TAR_CMD -xz -C "$innerdir" -f -
if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi
From 10d12f95ce0483594df18a75d04e7f6adede96b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sat, 18 Sep 2021 21:35:34 +0700
Subject: [PATCH 2/2] hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
---
common/hooks/do-extract/00-distfiles.sh | 32 ++++++++++++++-----------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/common/hooks/do-extract/00-distfiles.sh b/common/hooks/do-extract/00-distfiles.sh
index ca2011d5c45a..f14fa5823885 100644
--- a/common/hooks/do-extract/00-distfiles.sh
+++ b/common/hooks/do-extract/00-distfiles.sh
@@ -20,9 +20,7 @@ hook() {
fi
done
- if [ -n "$create_wrksrc" ]; then
- mkdir -p "${wrksrc}" || msg_error "$pkgver: failed to create wrksrc.\n"
- fi
+ rm -rf "$wrksrc"
# Disable trap on ERR; the code is smart enough to report errors and abort.
trap - ERR
@@ -31,6 +29,9 @@ hook() {
[ -z "$TAR_CMD" ] && TAR_CMD="$(command -v tar)"
[ -z "$TAR_CMD" ] && msg_error "xbps-src: no suitable tar cmd (bsdtar, tar)\n"
+ extractdir=$(mktemp -d "$XBPS_BUILDDIR/.extractdir-XXXXXXX") ||
+ msg_error "Cannot create temporary dir for do-extract\n"
+
msg_normal "$pkgver: extracting distfile(s), please wait...\n"
for f in ${distfiles}; do
@@ -73,12 +74,6 @@ hook() {
*) msg_error "$pkgver: unknown distfile suffix for $curfile.\n";;
esac
- if [ -n "$create_wrksrc" ]; then
- extractdir="$wrksrc"
- else
- extractdir="$XBPS_BUILDDIR"
- fi
-
case ${cursufx} in
tar|txz|tbz|tlz|tgz|crate)
$TAR_CMD -x --no-same-permissions --no-same-owner -f $srcdir/$curfile -C "$extractdir"
@@ -128,11 +123,7 @@ hook() {
fi
;;
txt)
- if [ "$create_wrksrc" ]; then
- cp -f $srcdir/$curfile "$extractdir"
- else
- msg_error "$pkgname: ${curfile##*.} files can only be extracted when create_wrksrc is set\n"
- fi
+ cp -f $srcdir/$curfile "$extractdir"
;;
7z)
if command -v 7z &>/dev/null; then
@@ -163,4 +154,17 @@ hook() {
;;
esac
done
+
+ # perhap below command is less magic?
+ # find "$extractdir" -mindepth 1 -maxdepth 1 -printf '1\n' | wc -l
+ shopt -s nullglob
+ set -- "$extractdir"/* "$extractdir"/.*
+ shopt -u nullglob
+ if [ $# = 3 ]; then
+ mv "$1" "$wrksrc" &&
+ rmdir "$extractdir"
+ else
+ mv "$extractdir" "$wrksrc"
+ fi ||
+ msg_error "$pkgver: failed to move sources to $wrksrc\n"
}
next prev parent reply other threads:[~2021-09-19 10:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-18 14:49 [PR PATCH] " sgn
2021-09-18 14:50 ` [PR PATCH] [Updated] " sgn
2021-09-18 15:06 ` q66
2021-09-18 19:36 ` Chocimier
2021-09-19 10:07 ` [PR PATCH] [Updated] " sgn
2021-09-19 10:13 ` sgn [this message]
2021-09-19 10:17 ` sgn
2021-09-19 10:37 ` [PR PATCH] [Updated] " sgn
2021-09-19 11:01 ` sgn
2021-09-19 11:13 ` sgn
2021-09-19 11:17 ` sgn
2021-09-19 11:26 ` [PR PATCH] [Updated] " sgn
2021-09-19 11:29 ` sgn
2021-09-19 11:37 ` sgn
2021-09-19 16:27 ` [PR PATCH] [Updated] " sgn
2021-09-19 16:38 ` sgn
2022-06-22 2:13 ` github-actions
2022-07-06 2:13 ` [PR PATCH] [Closed]: " github-actions
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210919101320.1QJRq8-gXRYuCG_zZaVdm3AzQR2GPiZF0cs7tS_P5I8@z \
--to=sgn@users.noreply.github.com \
--cc=ml@inbox.vuxu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).