Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Re: Globbing for Empty Directories?
- X-seq: zsh-workers 19741
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
- Subject: Re: PATCH: Re: Globbing for Empty Directories?
- Date: Tue, 6 Apr 2004 10:27:58 -0700
- Cc: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- In-reply-to: <20040401184336.DC34B8646@xxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <9E7AF602-8085-11D8-AA68-000502631FBD@xxxxxxxxxxxxxx> <20040401184336.DC34B8646@xxxxxxxxxxxxxxxxxxxxxxxx>
On Thu, Apr 01, 2004 at 07:43:35PM +0100, Peter Stephenson wrote:
> +qualnonemptydir(char *name, struct stat *buf, off_t days, char *str)
Here's a minor optimization for this function. It avoids reading the
directory if the st_nlink count is greater than 2 (since this must mean
that it has subdirs, and hence is not empty). I decided to move the
opendir() call down below this nlink test, so I had to pre-qualify the
name using S_ISDIR().
I believe that this is portable. Any objections/hesitations?
..wayne..
--- Src/glob.c 1 Apr 2004 18:33:22 -0000 1.32
+++ Src/glob.c 6 Apr 2004 17:04:48 -0000
@@ -2807,10 +2807,16 @@ qualsheval(char *name, struct stat *buf,
static int
qualnonemptydir(char *name, struct stat *buf, off_t days, char *str)
{
- DIR *dirh = opendir(name);
+ DIR *dirh;
struct dirent *de;
- if (dirh == NULL)
+ if (!S_ISDIR(buf->st_mode))
+ return 0;
+
+ if (buf->st_nlink > 2)
+ return 1;
+
+ if (!(dirh = opendir(name)))
return 0;
while ((de = readdir(dirh))) {
Messages sorted by:
Reverse Date,
Date,
Thread,
Author