Re: [dev] [stest] Hidden file processing

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat, 7 Oct 2017 12:25:39 +0200

On Sat, Oct 07, 2017 at 11:54:05AM +0200, Kamil Cholewiński wrote:
> Hi Hiltjo,
>
> On Fri, 06 Oct 2017, Hiltjo Posthuma <hiltjo_AT_codemadness.org> wrote:
> > Where is the patch?
>
> Attached, example below. However I would rather first discuss what
> should be the correct / expected behavior, before proposing a change.
> Going fast forward without a clear direction still gets you nowhere.
>
> > $ ./stest -d ~/.local
> > $ ./stest -ad ~/.local
> > /home/kamil/.local
> > $ ./stest -d .
> > $ ./stest -ad .
> > .
> > $ ./stest -f ./stest
> > ./stest
>
> <3,K.
>

I agree, but at the same time writing a patch shows both the bug-reporter
and hackers_AT_ more clear what the proposed patched behaviour would be.
For trivial patches it is better.

> commit a09638779e3235fc30e84a02e1a77b2319671b65
> Author: Kamil Cholewiński <harry666t_AT_gmail.com>
> Date: Fri Oct 6 15:52:18 2017 +0200
>
> [stest] is_hidden
>
> diff --git a/stest.c b/stest.c
> index 7a7b0bc..4da5230 100644
> --- a/stest.c
> +++ b/stest.c
> _AT_@ -2,6 +2,7 @@
> #include <sys/stat.h>
>
> #include <dirent.h>
> +#include <libgen.h>
> #include <limits.h>
> #include <stdio.h>
> #include <stdlib.h>
> _AT_@ -13,6 +14,7 @@ char *argv0;
>
> #define FLAG(x) (flag[(x)-'a'])
>
> +static int is_hidden(const char *path);
> static void test(const char *, const char *);
> static void usage(void);
>
> _AT_@ -20,12 +22,25 @@ static int match = 0;
> static int flag[26];
> static struct stat old, new;
>
> +static int
> +is_hidden(const char *path)
> +{
> + char *basec, *bname;
> + int hidden;
> +
> + basec = strdup(path);
> + bname = basename(basec);
> + hidden = bname[0] == '.';
> + free(basec);
> + return hidden;
> +}
> +
> static void
> test(const char *path, const char *name)
> {
> struct stat st, ln;
>
> - if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */
> + if ((!stat(path, &st) && (FLAG('a') || !is_hidden(path)) /* hidden files */
> && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */
> && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */
> && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */

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?

-- 
Kind regards,
Hiltjo
Received on Sat Oct 07 2017 - 12:25:39 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 07 2017 - 12:36:18 CEST