coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/2] test: Add unary operator -E: test that a file is an e


From: Mattias Andrée
Subject: Re: [PATCH v2 1/2] test: Add unary operator -E: test that a file is an empty directory
Date: Wed, 13 Apr 2016 17:57:10 +0200
User-agent: Claws Mail

On Wed, 13 Apr 2016 16:16:54 +0100
Stephane Chazelas <address@hidden> wrote:

> 2016-04-07 10:34:56 +0200, Mattias Andrée:
> [....]
> > +  if (!dir)
> > +    {
> > +      error (0, errno, "%s", dirname);
> > +      test_exit (TEST_FAILURE);
> > +    }  
> 
> Note that it means it makes it the first operator that
> would actually cause "test" to output something.
> 
> A test for non-empty without diagnostic output, like for
> [ -s ] may be preferable.

-s is of course already in use, but what is wrong with

  2> /dev/null

> 
> For most of the current operators, test returns true if
> the test can be performed and the test succeeds and
> returns false otherwise without an error message.
> 
> For instance, [ -e /secret/file ] would return false if
> "file" exists but you don't have search access to
> "/secret" and you don't get an error.

I don't believe there is anything wrong with that, but
of you want to be pedantic you should fail if you get EIO.
-s may also want to return success if you get EOVERFLOW.

> 
> 
> > +
> > +  while (errno = 0, (de = readdir (dir)))  
> 
> That also means that would be the first operator that has
> a side effect: update the access time of the directory.

Does that matter? If it does, we could use fdopendir instead
and open it with O_NOATIME. But that would make the solution
both more complex and less portable.

> 
> Note that GNU find has a "-empty" predicate.
> 
> Zsh has a "F" (for "full") glob qualifier. *(F) expands
> to the non-empty non-hidden directories in the current
> directory.
> 
> [ -F dir ], (for test for non-empty) could be an
> alternative. It doesn't seem to be taken by any of the
> "test" implementation I've checked.
> 

Sure, but -E may feel more natural, and we hardly need
both. We are much more familiar with thinking of an
empty directory as a separate file type. Additionally,
calling something, that contains at least one item is,
“full” is a misnomer.

Attachment: pgpgUnUxuBLPs.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]