Skip to contentSkip to conversation

kbuild: file-size: propagate ls failures

PATCH NAK Hamdy Abou El Anein 3 participants 3 messages Nov 3 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: file-size: propagate ls failures

From: Hamdy Abou El Anein <[email protected]>

When ls fails, set -- succeeds with no arguments and printf emits an empty line with status zero. A missing input is thus reported as a successful size query.

Capture the listing in a separate assignment under errexit before splitting its fields, so an ls failure stops the script.

Tested missing and empty files, a 123-byte file with spaces in its name, and a symbolic link. Successful output remains unchanged, including the link's own size.

AI assistance: ChatGPT/Codex identified the issue and prepared the change, commit message and executable regression tests.

Fixes a670b0b4aed1 ("kbuild: Use ls(1) instead of stat(1) to obtain file size")
---
 scripts/file-size.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/file-size.sh +4 -1
index 7eb7423416b..8fdc9060091 100755
@@ -1,4 +1,7 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-set -- $(ls -dn "$1")
+set -e
+
+size=$(ls -dn "$1")
+set -- $size
 printf '%s\n' "$5"
maintainer NAK
#1 lore raw
Quoted 9 lines · Hamdy Abou El Anein

From: Hamdy Abou El Anein <[email protected]>

When ls fails, set -- succeeds with no arguments and printf emits an empty line with status zero. A missing input is thus reported as a successful size query.

Capture the listing in a separate assignment under errexit before splitting its fields, so an ls failure stops the script.

Quoted 6 lines

Tested missing and empty files, a 123-byte file with spaces in its name, and a symbolic link. Successful output remains unchanged, including the link's own size.

AI assistance: ChatGPT/Codex identified the issue and prepared the change, commit message and executable regression tests.

While implementing shell scripts with 'set -e' is a good thing, we cannot apply this.

NACK

The reported issue is not reproducible with all usage of file-size.sh within the Linux tree. More important: if file-size.sh fails with an exit code, it even breaks some callers, which expect file-size.sh to succeed always. If you want to investigate, check all findings of file-size.sh within the tree.

Kind regards
Nicolas

#2 lore raw

Hi Nicolas,

Thank you for the review. I tested the script in isolation but missed the expectations of its callers. I understand why this change cannot be applied and will not resend it in this form.

Best regards,
Hamdy Abou El Anein

**Hamdy
Abou El Anein**

CIO / Senior Linux System Engineer

  [email protected]

  https://software-coders.ch/

  https://github.com/hamdyaea**

https://www.linkedin.com/in/hamdyaea/
**

The
content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.

Sent from Proton Mail for iOS.

-------- Original Message --------
On Tuesday, 11/03/26 at 21:56 Nicolas Schier <[email protected]> wrote:

Quoted 9 lines · Hamdy Abou El Anein

From: Hamdy Abou El Anein <[email protected]>

When ls fails, set -- succeeds with no arguments and printf emits an empty line with status zero. A missing input is thus reported as a successful size query.

Capture the listing in a separate assignment under errexit before splitting its fields, so an ls failure stops the script.

Quoted 6 lines

Tested missing and empty files, a 123-byte file with spaces in its name, and a symbolic link. Successful output remains unchanged, including the link's own size.

AI assistance: ChatGPT/Codex identified the issue and prepared the change, commit message and executable regression tests.

While implementing shell scripts with 'set -e' is a good thing, we cannot apply this.

NACK

The reported issue is not reproducible with all usage of file-size.sh within the Linux tree. More important: if file-size.sh fails with an exit code, it even breaks some callers, which expect file-size.sh to succeed always. If you want to investigate, check all findings of file-size.sh within the tree.

Kind regards
Nicolas