From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18326 invoked from network); 6 Apr 2004 17:28:24 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 6 Apr 2004 17:28:24 -0000 Received: (qmail 13516 invoked by alias); 6 Apr 2004 17:28:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19741 Received: (qmail 13503 invoked from network); 6 Apr 2004 17:28:02 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 6 Apr 2004 17:28:02 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 6 Apr 2004 17:28:2 -0000 Received: (qmail 1214 invoked from network); 6 Apr 2004 17:28:02 -0000 Received: from dsl3-63-249-88-2.cruzio.com (HELO binome.blorf.net) (63.249.88.2) by a.mx.sunsite.dk with SMTP; 6 Apr 2004 17:28:00 -0000 Received: by binome.blorf.net (Postfix, from userid 1000) id 60C154004; Tue, 6 Apr 2004 10:27:58 -0700 (PDT) Date: Tue, 6 Apr 2004 10:27:58 -0700 From: Wayne Davison To: Peter Stephenson Cc: Zsh hackers list Subject: Re: PATCH: Re: Globbing for Empty Directories? Message-ID: <20040406172758.GB10632@blorf.net> References: <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu> <20040401184336.DC34B8646@pwstephenson.fsnet.co.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="HlL+5n6rz5pIUxbD" Content-Disposition: inline In-Reply-To: <20040401184336.DC34B8646@pwstephenson.fsnet.co.uk> User-Agent: Mutt/1.5.5.1+cvs20040105i X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 --HlL+5n6rz5pIUxbD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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.. --HlL+5n6rz5pIUxbD Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="emptydir.patch" --- 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))) { --HlL+5n6rz5pIUxbD--