commit:     a379379aad4b075b5c7ec14e71a9701326013ae7
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 27 22:02:00 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 08:14:24 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a379379a

phase-helpers.sh: improve diagnostics for unpackable files

Just prior to the point at which unpacking commences, an -s test is
performed.  However, a file could exist while being zero bytes in size,
rendering the error message potentially confusing.

Improve it by first determining whether the file exists and is a regular
file (or a valid symlink to one). If it is not, die with an unambiguous
error message. Likewise, if the file is then found to be empty. Ideally,
one would not bother with testing the size but there may have been a
reason for doing so, such as a poorly implemented archiving utility.
Given that, let's leave it in for now.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/phase-helpers.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 86280a41d5..eca0a08c19 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -393,7 +393,13 @@ unpack() {
                else
                        die "Relative paths to unpack() must be prefixed with 
'./' in EAPI ${EAPI}"
                fi
-               [[ ! -s ${srcdir}${f} ]] && die "unpack: ${f} does not exist"
+
+               # Tolerate only regular files that are non-empty.
+               if [[ ! -f ${srcdir}${f} ]]; then
+                       die "unpack: ${f@Q} either does not exist or is not a 
regular file"
+               elif [[ ! -s ${srcdir}${f} ]]; then
+                       die "unpack: ${f@Q} cannot be unpacked because it is an 
empty file"
+               fi
 
                suffix_known=""
                case ${suffix,,} in

Reply via email to