zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Aaron Davies <agdavi01@louisville.edu>
Cc: Aaron Davies <agdavi01@netmail.louisville.edu>, zsh-users@sunsite.dk
Subject: Re: Globbing for Empty Directories?
Date: Mon, 29 Mar 2004 15:28:00 +0200	[thread overview]
Message-ID: <20040329132800.GA7384@DervishD> (raw)
In-Reply-To: <CA7477A0-8146-11D8-913F-000502631FBD@louisville.edu>

    Hi Aaron :)

 * Aaron Davies <agdavi01@louisville.edu> dixit:
> >>Is there a way to get empty directories from a glob pattern?
> >>'*(L0)' finds empty files, but doesn't work for dirs. I'm looking
> >>for something the equivalent of find's -empty argument, since I
> >>hate find with a passion and would love to never use it again.
> >    There is not, AFAIK. See the mailing list archives, I asked more
> >or less the same a few months ago. Testing for the number of links
> >won't work for directories :((
> Actually, I'm not sure of that. According to the info page for find, a 
> directory will always have two hard links, itself and it's "." pointer.

    That's true.
 
> Adding any subdirectories or files to it seems to increase the number 
> of links it has.

    Not under Linux, at least, although it may depend on the
filesystem type. For ext3, only subdirs increase the number of links
of a directory.

> So wouldn't *(/l2) find empty directories?

    It will find directories without subdirectories.

> Or is this hard-link policy not true on all systems?

    I have not tested in many systems, but Linux don't do it, and
I've not found any standard that require files to be links on the
directory. If you find any, please tell me to report the current
behaviour as a bug to Linux kernel developers, but looking at
findutils sources (that being GNU are intended to be very portable),
you can see the following:

{
  if (S_ISDIR (stat_buf->st_mode))
    {
      DIR *d;
      struct dirent *dp;
      boolean empty = true;

      errno = 0;
      d = opendir (rel_pathname);
      if (d == NULL)
	{
	  error (0, errno, "%s", pathname);
	  exit_status = 1;
	  return (false);
	}
      for (dp = readdir (d); dp; dp = readdir (d))
	{
	  if (dp->d_name[0] != '.'
	      || (dp->d_name[1] != '\0'
		  && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
	    {
	      empty = false;
	      break;
	    }
	}
      if (CLOSEDIR (d))
	{
	  error (0, errno, "%s", pathname);
	  exit_status = 1;
	  return (false);
	}
      return (empty);
    }
  else if (S_ISREG (stat_buf->st_mode))
    return (stat_buf->st_size == 0);
  else
    return (false);
}

    This is the code for '-empty', and as you can see, it examines
the files in the directory, not the number of links it has.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


  reply	other threads:[~2004-03-29 13:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-28  7:00 Aaron Davies
2004-03-28 19:21 ` Bart Schaefer
2004-03-28 20:13   ` Aaron Davies
2004-03-28 20:55     ` Bart Schaefer
2004-03-28 23:55       ` Aaron Davies
2004-03-29  0:54         ` Bart Schaefer
2004-03-29  6:05           ` Aaron Davies
2004-03-28 19:49 ` DervishD
2004-03-29  6:03   ` Aaron Davies
2004-03-29 13:28     ` DervishD [this message]
2004-03-29 15:19       ` Danek Duvall
2004-03-29 15:57         ` DervishD
2004-03-29 23:11       ` Aaron Davies
2004-03-29 23:24         ` DervishD
2004-03-31  1:44           ` Aaron Davies
2004-03-31  8:44             ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040329132800.GA7384@DervishD \
    --to=raul@pleyades.net \
    --cc=agdavi01@louisville.edu \
    --cc=agdavi01@netmail.louisville.edu \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).