Re: [dev] [stest] Hidden file processing

From: Kamil Cholewiński <harry666t_AT_gmail.com>
Date: Sat, 07 Oct 2017 19:52:29 +0200

On Sat, 07 Oct 2017, Hiltjo Posthuma <hiltjo_AT_codemadness.org> wrote:
> I think this is still not clear: what if a file is hidden due to its path?
> for example: $HOME/.config/somefile
>
> should it be visible or not?
>
> the stest man page uses the term "file" but "path" is meant.
> for example:
> -d Test that files are directories.
>
> I think the -a option looks out of place to be honest. Should it be removed
> or at the very least better documented?

I've meditated on this and I have two propositions.

I believe the original motivation for including "-a" at all was to
mirror the behavior of plain "ls". "stest -l ." will in fact work very
similarly to "ls", and "stest -la ." will match the behavior of "ls -a".

Otherwise, stest in any other mode will only look at what it gets from
stat(2), and IMHO any filename/path processing feels out of place there.

So the proposition #1 is to match the behavior of "ls -d", unless using
"stest -l". Currently:

> $ ls -a
> . .. .hidden dir file
> $ stest -f * .* . ..
> file
> $ stest -d * .* . ..
> dir
> $ stest -af * .* . ..
> file
> .hidden
> $ stest -ad * .* . ..
> dir
> .
> ..
> $ stest -l .
> dir
> file
> $ stest -al .
> .
> ..
> .hidden
> dir
> file

Proposed behavior:

> $ stest -f * .* . ..
> file
> .hidden
> $ stest -d * .* . ..
> dir
> .
> ..
> $ stest -l .
> dir
> file
> $ stest -al .
> .
> ..
> .hidden
> dir
> file

And for the manual:

> -a In conjunction with -l, also test hidden files.
> [...]
> -l Test the contents of a directory given as an argument,
> ignoring hidden files (unless -a is also specified).

Q&D diff:

- if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */
+ if ((!stat(path, &st)
+ && (!FLAG('l') || (FLAG('a') || name[0] != '.')) /* hidden files */

Seems to be doing the right thing.

Proposal 2 is to get rid of "-a" entirely (or make it a no-op to avoid
breaking existing scripts) and always process hidden files.

<3,K.
Received on Sat Oct 07 2017 - 19:52:29 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 07 2017 - 20:00:18 CEST