* PATCH: Re: Globbing for Empty Directories?
[not found] <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu>
@ 2004-04-01 18:43 ` Peter Stephenson
2004-04-01 19:26 ` DervishD
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Peter Stephenson @ 2004-04-01 18:43 UTC (permalink / raw)
To: Zsh hackers list
The only non-trivial part is finding a suitable qualifier.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.46
diff -u -r1.46 expn.yo
--- Doc/Zsh/expn.yo 8 May 2003 10:30:49 -0000 1.46
+++ Doc/Zsh/expn.yo 1 Apr 2004 18:27:22 -0000
@@ -1630,6 +1630,9 @@
item(tt(/))(
directories
)
+item(tt(F))(
+`full' (i.e. non-empty) directories
+)
item(tt(.))(
plain files
)
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.31
diff -u -r1.31 glob.c
--- Src/glob.c 6 Oct 2003 22:42:39 -0000 1.31
+++ Src/glob.c 1 Apr 2004 18:27:28 -0000
@@ -1322,6 +1322,9 @@
func = qualmodeflags;
data = qgetmodespec(&s);
break;
+ case 'F':
+ func = qualnonemptydir;
+ break;
case 'M':
/* Mark directories with a / */
if ((gf_markdirs = !(sense & 1)))
@@ -2799,3 +2802,24 @@
}
return 0;
}
+
+/**/
+static int
+qualnonemptydir(char *name, struct stat *buf, off_t days, char *str)
+{
+ DIR *dirh = opendir(name);
+ struct dirent *de;
+
+ if (dirh == NULL)
+ return 0;
+
+ while ((de = readdir(dirh))) {
+ if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
+ closedir(dirh);
+ return 1;
+ }
+ }
+
+ closedir(dirh);
+ return 0;
+}
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Re: Globbing for Empty Directories?
2004-04-01 18:43 ` PATCH: Re: Globbing for Empty Directories? Peter Stephenson
@ 2004-04-01 19:26 ` DervishD
2004-04-01 22:49 ` Geoff Wing
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: DervishD @ 2004-04-01 19:26 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
Hi Peter :)
* Peter Stephenson <pws@pwstephenson.fsnet.co.uk> dixit:
> The only non-trivial part is finding a suitable qualifier.
Thanks, it is quite useful :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Re: Globbing for Empty Directories?
2004-04-01 18:43 ` PATCH: Re: Globbing for Empty Directories? Peter Stephenson
2004-04-01 19:26 ` DervishD
@ 2004-04-01 22:49 ` Geoff Wing
2004-04-02 2:02 ` Geoff Wing
2004-04-06 17:27 ` Wayne Davison
2004-04-06 17:55 ` Wayne Davison
3 siblings, 1 reply; 7+ messages in thread
From: Geoff Wing @ 2004-04-01 22:49 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson <pws@pwstephenson.fsnet.co.uk> typed:
: + while ((de = readdir(dirh))) {
: + if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
: + closedir(dirh);
: + return 1;
: + }
: + }
Really?
Regards,
Geoff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Re: Globbing for Empty Directories?
2004-04-01 22:49 ` Geoff Wing
@ 2004-04-02 2:02 ` Geoff Wing
0 siblings, 0 replies; 7+ messages in thread
From: Geoff Wing @ 2004-04-02 2:02 UTC (permalink / raw)
To: zsh-workers
Geoff Wing <mason@primenet.com.au> typed:
: Peter Stephenson <pws@pwstephenson.fsnet.co.uk> typed:
:: + while ((de = readdir(dirh))) {
:: + if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
:: + closedir(dirh);
:: + return 1;
:: + }
:: + }
:
: Really?
Oh, my braino. Sorry for the noise.
Regards,
Geoff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Re: Globbing for Empty Directories?
2004-04-01 18:43 ` PATCH: Re: Globbing for Empty Directories? Peter Stephenson
2004-04-01 19:26 ` DervishD
2004-04-01 22:49 ` Geoff Wing
@ 2004-04-06 17:27 ` Wayne Davison
2004-04-06 17:41 ` Peter Stephenson
2004-04-06 17:55 ` Wayne Davison
3 siblings, 1 reply; 7+ messages in thread
From: Wayne Davison @ 2004-04-06 17:27 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 517 bytes --]
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..
[-- Attachment #2: emptydir.patch --]
[-- Type: text/plain, Size: 507 bytes --]
--- 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))) {
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Re: Globbing for Empty Directories?
2004-04-06 17:27 ` Wayne Davison
@ 2004-04-06 17:41 ` Peter Stephenson
0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2004-04-06 17:41 UTC (permalink / raw)
To: Zsh hackers list
Wayne Davison wrote:
> 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().
Looks OK to me.
pws
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Re: Globbing for Empty Directories?
2004-04-01 18:43 ` PATCH: Re: Globbing for Empty Directories? Peter Stephenson
` (2 preceding siblings ...)
2004-04-06 17:27 ` Wayne Davison
@ 2004-04-06 17:55 ` Wayne Davison
3 siblings, 0 replies; 7+ messages in thread
From: Wayne Davison @ 2004-04-06 17:55 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 143 bytes --]
I thought it would be nice to test the new 'F'ull-directory glob
modifier, so I'm planning to commit these changes to D02glob.ztst.
..wayne..
[-- Attachment #2: globtest.patch --]
[-- Type: text/plain, Size: 1656 bytes --]
--- Test/D02glob.ztst 3 Dec 2003 10:54:36 -0000 1.3
+++ Test/D02glob.ztst 6 Apr 2004 17:33:46 -0000
@@ -2,8 +2,8 @@
%prep
mkdir glob.tmp
- mkdir glob.tmp/dir1
- mkdir glob.tmp/dir2
+ mkdir glob.tmp/dir{1,2,3,4}
+ mkdir glob.tmp/dir3/subdir
: >glob.tmp/{,{dir1,dir2}/}{a,b,c}
globtest () { $ZTST_testdir/../Src/zsh -f $ZTST_srcdir/../Misc/$1 }
@@ -265,11 +265,11 @@
( regress_absolute_path_and_core_dump )
0:exclusions regression test
>
->glob.tmp/a glob.tmp/b glob.tmp/c glob.tmp/dir1 glob.tmp/dir1/a glob.tmp/dir1/b glob.tmp/dir1/c glob.tmp/dir2 glob.tmp/dir2/a glob.tmp/dir2/b glob.tmp/dir2/c
+>glob.tmp/a glob.tmp/b glob.tmp/c glob.tmp/dir1 glob.tmp/dir1/a glob.tmp/dir1/b glob.tmp/dir1/c glob.tmp/dir2 glob.tmp/dir2/a glob.tmp/dir2/b glob.tmp/dir2/c glob.tmp/dir3 glob.tmp/dir3/subdir glob.tmp/dir4
print glob.tmp/*(/)
0:Just directories
->glob.tmp/dir1 glob.tmp/dir2
+>glob.tmp/dir1 glob.tmp/dir2 glob.tmp/dir3 glob.tmp/dir4
print glob.tmp/*(.)
0:Just files
@@ -281,7 +281,7 @@
print glob.tmp/**/(:h)
0:Head modifier
->. glob.tmp glob.tmp
+>. glob.tmp glob.tmp glob.tmp glob.tmp glob.tmp/dir3
print glob.tmp(:r)
0:Remove extension modifier
@@ -289,5 +289,16 @@
print glob.tmp/*(:s/./_/)
0:Substitute modifier
->glob_tmp/a glob_tmp/b glob_tmp/c glob_tmp/dir1 glob_tmp/dir2
+>glob_tmp/a glob_tmp/b glob_tmp/c glob_tmp/dir1 glob_tmp/dir2 glob_tmp/dir3 glob_tmp/dir4
+ print glob.tmp/*(F)
+0:Just full dirs
+>glob.tmp/dir1 glob.tmp/dir2 glob.tmp/dir3
+
+ print glob.tmp/*(^F)
+0:Omit full dirs
+>glob.tmp/a glob.tmp/b glob.tmp/c glob.tmp/dir4
+
+ print glob.tmp/*(/^F)
+0:Just empty dirs
+>glob.tmp/dir4
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-04-06 17:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu>
2004-04-01 18:43 ` PATCH: Re: Globbing for Empty Directories? Peter Stephenson
2004-04-01 19:26 ` DervishD
2004-04-01 22:49 ` Geoff Wing
2004-04-02 2:02 ` Geoff Wing
2004-04-06 17:27 ` Wayne Davison
2004-04-06 17:41 ` Peter Stephenson
2004-04-06 17:55 ` Wayne Davison
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).