[BusyBox] Problem with ls

Richard June rjune at imagestream-is.com
Mon Nov 27 18:38:17 UTC 2000


Well Matt, you're cool, I was just looking for direction, you gave me
the fix, Everything seems to work now, 'ls -aR', 'ls -aR *', and 'ls -aR
.' all recurse properly, the only problem was I had to apply the patch
by hand, Here's the patch for 0.47
-------------- next part --------------
--- ls.c	Sun Nov 26 08:54:02 2000
+++ ls.c.new	Sun Nov 26 08:53:14 2000
@@ -127,6 +127,7 @@
 
 #define SPLIT_DIR		0
 #define SPLIT_FILE		1
+#define SPLIT_SUBDIR	2
 
 #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
 #define TYPECHAR(mode)  ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
@@ -211,6 +212,12 @@
 }
 
 /*----------------------------------------------------------------------*/
+static int is_subdir(struct dnode *dn)
+{
+	return (S_ISDIR(dn->dstat.st_mode) && strcmp(dn->name, ".") != 0 &&
+	                strcmp(dn->name, "..") != 0);
+}
+
 int countdirs(struct dnode **dn, int nfiles)
 {
 	int i, dirs;
@@ -224,6 +231,18 @@
 	return(dirs);
 }
 
+int countsubdirs(struct dnode **dn, int nfiles)
+{
+	int i, subdirs;
+
+	if (dn == NULL || nfiles < 1) return 0;
+	subdirs = 0;
+	for (i = 0; i < nfiles; i++)
+		if (is_subdir(dn[i]))
+			subdirs++;
+	return subdirs;
+}
+
 int countfiles(struct dnode **dnp)
 {
 	int nfiles;
@@ -271,9 +290,13 @@
 	if (dn==NULL || nfiles < 1) return(NULL);
 
 	/* count how many dirs and regular files there are */
-	dncnt= countdirs(dn, nfiles); /* assume we are looking for dirs */
-	if (which != SPLIT_DIR)
-		dncnt= nfiles - dncnt;  /* looking for files */
+	if (which == SPLIT_SUBDIR)
+		dncnt = countsubdirs(dn, nfiles);
+	else {
+		dncnt= countdirs(dn, nfiles); /* assume we are looking for dirs */
+		if (which == SPLIT_FILE)
+			dncnt= nfiles - dncnt;  /* looking for files */
+	}
 
 	/* allocate a file array and a dir array */
 	dnp= dnalloc(dncnt);
@@ -284,6 +307,10 @@
 			if (S_ISDIR(dn[i]->dstat.st_mode)) {
 				dnp[d++]= dn[i];
 			}  /* else skip the file */
+		} else if (which == SPLIT_SUBDIR) {
+			if (is_subdir(dn[i])) {
+				dnp[d++]= dn[i];
+			}  /* else skip the file or dir */
 		} else {
 			if (!(S_ISDIR(dn[i]->dstat.st_mode))) {
 				dnp[d++]= dn[i];
@@ -430,8 +457,8 @@
 #ifdef BB_FEATURE_LS_RECURSIVE
 			if (disp_opts & DISP_RECURSIVE) {
 				/* recursive- list the sub-dirs */
-				dnd= splitdnarray(subdnp, nfiles, SPLIT_DIR);
-				dndirs= countdirs(subdnp, nfiles);
+					dnd= splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
+					dndirs= countsubdirs(subdnp, nfiles);
 				if (dndirs > 0) {
 					shellsort(dnd, dndirs);
 					showdirs(dnd, dndirs);


More information about the busybox mailing list