Re: [PATCH] find: Fix broken -ls, add test.

2026-07-23 Thread James Youngman
I'm pushing the attached patch, which I hope will fix the problem.

On Thu, Jul 23, 2026 at 8:24 PM James Youngman  wrote:
>
> Yes, the test reproducibly passes for me.   But the filesystem I am
> using is ZFS:
>
> $ yes "" | sed -e '765 q'> /tmp/small-text-file.txt ; \
>   dd if=/dev/urandom bs=765 of=/tmp/random-data.bin  count=1 ; \
>   cp /tmp/random-data.bin /tmp/small-text-file.txt . ; \
>   find  \
> /tmp/random-data.bin random-data.bin /tmp/small-text-file.txt
> small-text-file.txt  \
> -printf '%%k=%k %%b=%b %s %p\n' ; \
>   sha1sum /tmp/random-data.bin random-data.bin
> /tmp/small-text-file.txt small-text-file.txt
> 1+0 records in
> 1+0 records out
> 765 bytes copied, 3.9558e-05 s, 19.3 MB/s
> %k=4 %b=8 765 /tmp/random-data.bin
> %k=5 %b=9 765 random-data.bin
> %k=4 %b=8 765 /tmp/small-text-file.txt
> %k=1 %b=1 765 small-text-file.txt
> 0156e7e4ea8f26c91c5de2f4337d8e1d44e7c556  /tmp/random-data.bin
> 0156e7e4ea8f26c91c5de2f4337d8e1d44e7c556  random-data.bin
> 38957bd663f7efc364ac7c8ed3589fa69520b9e4  /tmp/small-text-file.txt
> 38957bd663f7efc364ac7c8ed3589fa69520b9e4  small-text-file.txt
> $ stat /tmp/random-data.bin random-data.bin /tmp/small-text-file.txt
> small-text-file.txt
>   File: /tmp/random-data.bin
>   Size: 765Blocks: 8  IO Block: 4096   regular file
> Device: 253,2 Inode: 19  Links: 1
> Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
> Access: 2026-07-23 20:21:50.226425401 +0100
> Modify: 2026-07-23 20:21:50.222425458 +0100
> Change: 2026-07-23 20:21:50.222425458 +0100
>  Birth: 2026-07-23 20:17:57.985621969 +0100
>   File: random-data.bin
>   Size: 765Blocks: 9  IO Block: 1024   regular file
> Device: 0,41 Inode: 5342459 Links: 1
> Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
> Access: 2026-07-23 20:21:50.230425347 +0100
> Modify: 2026-07-23 20:21:50.226425401 +0100
> Change: 2026-07-23 20:21:50.226425401 +0100
>  Birth: 2026-07-23 20:17:57.985621969 +0100
>   File: /tmp/small-text-file.txt
>   Size: 765Blocks: 8  IO Block: 4096   regular file
> Device: 253,2 Inode: 16  Links: 1
> Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
> Access: 2026-07-23 20:21:50.226425401 +0100
> Modify: 2026-07-23 20:21:50.218425513 +0100
> Change: 2026-07-23 20:21:50.218425513 +0100
>  Birth: 2026-07-23 20:17:57.981622024 +0100
>   File: small-text-file.txt
>   Size: 765Blocks: 1  IO Block: 1024   regular file
> Device: 0,41 Inode: 5342460 Links: 1
> Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
> Access: 2026-07-23 20:21:50.230425347 +0100
> Modify: 2026-07-23 20:21:50.226425401 +0100
> Change: 2026-07-23 20:21:50.226425401 +0100
>  Birth: 2026-07-23 20:17:57.985621969 +0100
From eaa3ba5a63b569dbf1a4b1389963f734ebe7edd3 Mon Sep 17 00:00:00 2001
From: James Youngman 
Date: Thu, 23 Jul 2026 20:28:35 +0100
Subject: [PATCH] find: another fix for the still-broken -ls test.

The remaining problem is that the struct stat.st_blocks value for a
file depends on implementation details of the file system and so we
cannot expect to create a file and check the resuting st_blocks value
against a fixed expectation.

* tests/find/ls-format-file.sh (AWK script): do not check the value in
$2, the block count, as this will vary across file systems.  Record in
the test log the output of various other commands which examine the
output of -printf %b, -printf %k and -ls for the file with
POSIXLY_CORRECT set and with it unset.
(with_512_byte_blocks): shell function which sets up the environment
such that GNU find will use 512-byte blocks and runs a command.
---
 tests/find/ls-format-file.sh | 59 +---
 1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/tests/find/ls-format-file.sh b/tests/find/ls-format-file.sh
index cee3737e..b568350b 100755
--- a/tests/find/ls-format-file.sh
+++ b/tests/find/ls-format-file.sh
@@ -22,6 +22,10 @@ print_ver_ find
 # Ensure that find does not generally skip warnings due to POSIX requirements.
 unset POSIXLY_CORRECT
 
+with_512_byte_blocks() {
+env -u BLOCK_SIZE -u BLOCKSIZE POSIXLY_CORRECT=1 "$@"
+}
+
 # We want to check the date in the output of -ls, so ensure we're
 # dealing with the C locale only.
 LC_ALL=C
@@ -121,16 +125,11 @@ then
 skip_ "failed to change group of ${testfile} to ${group_owner}"
 fi
 
-# Remember the file's inode number and block count.
+# Remember the file's inode number.
 inum="$( find "${testfile}" -printf '%i\n' )"
-blocks_expected="$( ls -s "${testfile}" | sed -e "s/${testfile}//g" )"
-# The system's value of BLOCKSIZE is implementation-dependent
-# ("ls -k" forces ls to use 1KiB blocks, but -ls is intended
-# to look like the output of ls -dils, without -k)
-
 
 # Generate the ls output.
-find "${testfile}" -ls > output.txt
+with_512_byte_blocks find "${testfile}" -ls > output.txt
 
 # Show the reader of the test log 

Re: [PATCH] find: Fix broken -ls, add test.

2026-07-23 Thread James Youngman
Yes, the test reproducibly passes for me.   But the filesystem I am
using is ZFS:

$ yes "" | sed -e '765 q'> /tmp/small-text-file.txt ; \
  dd if=/dev/urandom bs=765 of=/tmp/random-data.bin  count=1 ; \
  cp /tmp/random-data.bin /tmp/small-text-file.txt . ; \
  find  \
/tmp/random-data.bin random-data.bin /tmp/small-text-file.txt
small-text-file.txt  \
-printf '%%k=%k %%b=%b %s %p\n' ; \
  sha1sum /tmp/random-data.bin random-data.bin
/tmp/small-text-file.txt small-text-file.txt
1+0 records in
1+0 records out
765 bytes copied, 3.9558e-05 s, 19.3 MB/s
%k=4 %b=8 765 /tmp/random-data.bin
%k=5 %b=9 765 random-data.bin
%k=4 %b=8 765 /tmp/small-text-file.txt
%k=1 %b=1 765 small-text-file.txt
0156e7e4ea8f26c91c5de2f4337d8e1d44e7c556  /tmp/random-data.bin
0156e7e4ea8f26c91c5de2f4337d8e1d44e7c556  random-data.bin
38957bd663f7efc364ac7c8ed3589fa69520b9e4  /tmp/small-text-file.txt
38957bd663f7efc364ac7c8ed3589fa69520b9e4  small-text-file.txt
$ stat /tmp/random-data.bin random-data.bin /tmp/small-text-file.txt
small-text-file.txt
  File: /tmp/random-data.bin
  Size: 765Blocks: 8  IO Block: 4096   regular file
Device: 253,2 Inode: 19  Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
Access: 2026-07-23 20:21:50.226425401 +0100
Modify: 2026-07-23 20:21:50.222425458 +0100
Change: 2026-07-23 20:21:50.222425458 +0100
 Birth: 2026-07-23 20:17:57.985621969 +0100
  File: random-data.bin
  Size: 765Blocks: 9  IO Block: 1024   regular file
Device: 0,41 Inode: 5342459 Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
Access: 2026-07-23 20:21:50.230425347 +0100
Modify: 2026-07-23 20:21:50.226425401 +0100
Change: 2026-07-23 20:21:50.226425401 +0100
 Birth: 2026-07-23 20:17:57.985621969 +0100
  File: /tmp/small-text-file.txt
  Size: 765Blocks: 8  IO Block: 4096   regular file
Device: 253,2 Inode: 16  Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
Access: 2026-07-23 20:21:50.226425401 +0100
Modify: 2026-07-23 20:21:50.218425513 +0100
Change: 2026-07-23 20:21:50.218425513 +0100
 Birth: 2026-07-23 20:17:57.981622024 +0100
  File: small-text-file.txt
  Size: 765Blocks: 1  IO Block: 1024   regular file
Device: 0,41 Inode: 5342460 Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1027/   james)   Gid: ( 1027/   james)
Access: 2026-07-23 20:21:50.230425347 +0100
Modify: 2026-07-23 20:21:50.226425401 +0100
Change: 2026-07-23 20:21:50.226425401 +0100
 Birth: 2026-07-23 20:17:57.985621969 +0100



Re: [PATCH] find: Fix broken -ls, add test.

2026-07-22 Thread Bernhard Voelker

On 7/13/26 12:18, James Youngman wrote:

Thanks for these fixes.  I sent a couple of follow-up improvements.


Hi James,

thanks - still 'tests/find/ls-format-file.sh' is failing here.

The relevant part is:

  + find lsme -printf '%9i %6b %M %3n %-8u %-8g %8s %3Tb %2Td %5TY %p\n'
  + compare printf-output.txt output.txt
  + compare_dev_null_ printf-output.txt output.txt
  + test 2 = 2
  + test xprintf-output.txt = x/dev/null
  + test xoutput.txt = x/dev/null
  + return 2
  + case $? in
  + compare_ printf-output.txt output.txt
  + LC_ALL=C
  + diff -u printf-output.txt output.txt
  --- printf-output.txt 2026-07-22 23:25:29.952544221 +0200
  +++ output.txt2026-07-22 23:25:29.941544072 +0200
  @@ -1 +1 @@
  -  6042709  8 -rw---   1 bernyusers 765 Mar 14  1992 lsme
  +  6042709  4 -rw---   1 bernyusers 765 Mar 14  1992 lsme
  + fail=1

This means -printf '%b' yields 8 because it's using 512 blocksize while -ls uses
a blocksize of 1024.

Here is the output for -ls, %b, %k and system ls for comparison - depending
on POSIXLY_CORRECT:


  $ env POSIXLY_CORRECT=1 \
  find/find lsme \
-ls \
-printf '%9i %6b %M %3n %-8u %-8g %8s %3Tb %2Td %5TY %p\n' \
-printf "%9i %6k %M %3n %-8u %-8g %8s %3Tb %2Td %5TY %p\n" \
-exec /bin/ls -dils '{}' \;
5780631  8 -rw-r--r--   1 bernyusers 765 Jul 22 20:54 lsme
5780631  8 -rw-r--r--   1 bernyusers 765 Jul 22  2026 lsme
5780631  4 -rw-r--r--   1 bernyusers 765 Jul 22  2026 lsme
  5780631 8 -rw-r--r-- 1 berny users 765 Jul 22 20:54 lsme

  $ env -u POSIXLY_CORRECT \
  find/find lsme \
-ls \
-printf '%9i %6b %M %3n %-8u %-8g %8s %3Tb %2Td %5TY %p\n' \
-printf "%9i %6k %M %3n %-8u %-8g %8s %3Tb %2Td %5TY %p\n" \
-exec /bin/ls -dils '{}' \;
5780631  4 -rw-r--r--   1 bernyusers 765 Jul 22 20:54 lsme
5780631  8 -rw-r--r--   1 bernyusers 765 Jul 22  2026 lsme
5780631  4 -rw-r--r--   1 bernyusers 765 Jul 22  2026 lsme
  5780631 4 -rw-r--r-- 1 berny users 765 Jul 22 20:54 lsme

FWIW: I'm using an 'ext4' filesystem here, and this is the output of the 
statx() syscall:

  $ strace -ve statx /bin/stat lsme 2>&1 | sed 1q
  statx(AT_FDCWD, "lsme", 
AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_ALL, \
{stx_mask=STATX_ALL|STATX_MNT_ID, \
 stx_blksize=4096, \
 stx_attributes=0, \
 stx_nlink=1, \
 stx_uid=1000, \
 stx_gid=100, \
 stx_mode=S_IFREG|0644, \
 stx_ino=5780631, \
 stx_size=765, \
 stx_blocks=8, \
 
stx_attributes_mask=STATX_ATTR_COMPRESSED|STATX_ATTR_IMMUTABLE|STATX_ATTR_APPEND|STATX_ATTR_NODUMP|\
   
STATX_ATTR_ENCRYPTED|STATX_ATTR_AUTOMOUNT|STATX_ATTR_MOUNT_ROOT|STATX_ATTR_VERITY|STATX_ATTR_DAX,
 \
 stx_atime={tv_sec=1784746447, tv_nsec=353879572} /* 
2026-07-22T20:54:07.353879572+0200 */, \
 stx_btime={tv_sec=1784746447, tv_nsec=353879572} /* 
2026-07-22T20:54:07.353879572+0200 */, \
 stx_ctime={tv_sec=1784746447, tv_nsec=354879586} /* 
2026-07-22T20:54:07.354879586+0200 */, \
 stx_mtime={tv_sec=1784746447, tv_nsec=354879586} /* 
2026-07-22T20:54:07.354879586+0200 */, \
 stx_rdev_major=0, \
 stx_rdev_minor=0, \
 stx_dev_major=8, \
 stx_dev_minor=5, \
 stx_mnt_id=0x2a}) = 0

I'm confused why this test is working for you.  Can you reproduce this?
Do you have a different filesystem type with other block sizes?

Changing from %b to %k helps here, but I'd rather like to understand what 
happens on your side.

diff --git a/tests/find/ls-format-file.sh b/tests/find/ls-format-file.sh
index cee3737e..b624 100755
--- a/tests/find/ls-format-file.sh
+++ b/tests/find/ls-format-file.sh
@@ -309,7 +309,7 @@ fi
 # Generate "by hand" in the file printf-output.txt some output which
 # should match the output of -ls.
 rm -f -- printf-output.txt
-if ! find "${testfile}" -printf '%9i %6b %M %3n %-8u %-8g %8s %3Tb %2Td %5TY 
%p\n' > printf-output.txt
+if ! find "${testfile}" -printf '%9i %6k %M %3n %-8u %-8g %8s %3Tb %2Td %5TY 
%p\n' > printf-output.txt
 then
 framework_failure_ "unable to create printf-output.txt"
 fi


Thanks & have a nice day,
Berny++ initial_cwd_=/home/berny/findutils
+++ testdir_prefix_
+++ printf gt
++ pfx_=gt
+++ mktempd_ /home/berny/findutils gt-ls-format-file.sh.
+++ case $# in
+++ destdir_=/home/berny/findutils
+++ template_=gt-ls-format-file.sh.
+++ MAX_TRIES_=4
+++ case $destdir_ in
+++ destdir_slash_=/home/berny/findutils/
+++ case $template_ in
 unset TMPDIR
+++ d=/home/berny/findutils/gt-ls-format-file.sh.sGo8
+++ case $d in
+++ :
+++ test -d /home/berny/findutils/gt-ls-format-file.sh.sGo8
 ls -dgo /home/berny/findutils/gt-ls-format-file.sh.sGo8
+++ perms='drwx-- 2 4096 Jul 22 23:49 /home/berny/findutils/gt-ls-format-file.sh.sGo8'
+++ case $perms in
+++ :
+++ echo 

Re: [PATCH] find: Fix broken -ls, add test.

2026-07-13 Thread James Youngman
On Mon, Jul 13, 2026 at 7:45 AM Bernhard Voelker
 wrote:
> I'll check a bit more on the patches later.

Thanks for these fixes.  I sent a couple of follow-up improvements.  I
will wait a while before pushing them to give you a chance to review
them.

James.



Re: [PATCH] find: Fix broken -ls, add test.

2026-07-12 Thread Bernhard Voelker

On 7/13/26 02:49, James Youngman wrote:

Because the public tree was already broken (i.e. tests did not pass) I
pushed this patch without waiting for feedback.   If there are
problems with it at least they're less bad.

Sorry about the breakage,


Thanks for fixing.

As a quick fix, I pushed the attached follow-up commit to fix the new tests.
- fix group check: I assume that you locally are using a group name
  which is identical to your user name?
- tests shall be executable, otherwise syntax-check complains.

I'll check a bit more on the patches later.

Have a nice day,
Berny
From 635998b4d9c86ae1ba70c058b8f022a2ce80ab17 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker 
Date: Mon, 13 Jul 2026 08:40:58 +0200
Subject: [PATCH] tests: fix new find -ls tests

* tests/find/ls-format-symlink.sh: Make executable.
* tests/find/ls-format-file.sh: Likewise.
Additionally, compare with 'gowner' for the group name.
---
 tests/find/ls-format-file.sh| 4 ++--
 tests/find/ls-format-symlink.sh | 0
 2 files changed, 2 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 tests/find/ls-format-file.sh
 mode change 100644 => 100755 tests/find/ls-format-symlink.sh

diff --git a/tests/find/ls-format-file.sh b/tests/find/ls-format-file.sh
old mode 100644
new mode 100755
index b5772536..9a9989d0
--- a/tests/find/ls-format-file.sh
+++ b/tests/find/ls-format-file.sh
@@ -170,9 +170,9 @@ NR == 1 {
 printf("%s: owner %s looks OK\n", ME, st_uid);
   }
   # field 6 is the group owner
-  if (st_gid != uowner) {
+  if (st_gid != gowner) {
 rv=1
-printf("%s: failed test: expected group owner [%s], got [%s]\n", ME, uowner, st_gid);
+printf("%s: failed test: expected group owner [%s], got [%s]\n", ME, gowner, st_gid);
   } else {
 printf("%s: group owner %s looks OK\n", ME, st_gid);
   }
diff --git a/tests/find/ls-format-symlink.sh b/tests/find/ls-format-symlink.sh
old mode 100644
new mode 100755
-- 
2.54.0



Re: [PATCH] find: Fix broken -ls, add test.

2026-07-12 Thread James Youngman
Because the public tree was already broken (i.e. tests did not pass) I
pushed this patch without waiting for feedback.   If there are
problems with it at least they're less bad.

Sorry about the breakage,

James.