Mercurial > hg > toybox
comparison toys/ls.c @ 570:83702597fd31
Require -R to recurse, but descend into directories listed on command line.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 24 Apr 2012 05:48:03 -0500 |
parents | 2e0367cb9585 |
children | 1a06fcaa1775 |
comparison
equal
deleted
inserted
replaced
569:2e0367cb9585 | 570:83702597fd31 |
---|---|
155 unsigned long dtlen = 0, ul = 0; | 155 unsigned long dtlen = 0, ul = 0; |
156 unsigned width, flags = toys.optflags, totals[6], len[6]; | 156 unsigned width, flags = toys.optflags, totals[6], len[6]; |
157 int showdirs = 1; | 157 int showdirs = 1; |
158 | 158 |
159 // Figure out if we should show directories and current directory name | 159 // Figure out if we should show directories and current directory name |
160 if (indir == TT.files) showdirs = (flags & (FLAG_d|FLAG_R)); | 160 if (indir == TT.files) |
161 showdirs = (flags & (FLAG_d|FLAG_R)) || indir->parent; | |
161 if (indir != TT.files || (indir->parent && (flags & FLAG_R))) { | 162 if (indir != TT.files || (indir->parent && (flags & FLAG_R))) { |
162 char *path = dirtree_path(indir, 0); | 163 char *path = dirtree_path(indir, 0); |
163 | 164 |
164 if (TT.again++) xputc('\n'); | 165 if (TT.again++) xputc('\n'); |
165 xprintf("%s:\n", path); | 166 xprintf("%s:\n", path); |
270 | 271 |
271 for (ul = 0; ul<dtlen; free(sort[ul++])) { | 272 for (ul = 0; ul<dtlen; free(sort[ul++])) { |
272 // TODO follow symlinks when? | 273 // TODO follow symlinks when? |
273 if (!S_ISDIR(sort[ul]->st.st_mode) || dirtree_isdotdot(sort[ul])) | 274 if (!S_ISDIR(sort[ul]->st.st_mode) || dirtree_isdotdot(sort[ul])) |
274 continue; | 275 continue; |
275 if (indir == TT.files || (flags & FLAG_R)) { | 276 if (!indir->parent || (flags & FLAG_R)) { |
276 int fd = openat(indir->data, sort[ul]->name, 0); | 277 int fd = openat(indir->data, sort[ul]->name, 0); |
277 | 278 |
278 sort[ul]->data = dup(fd); | 279 sort[ul]->data = dup(fd); |
279 dirtree_recurse(sort[ul], filter); | 280 dirtree_recurse(sort[ul], filter); |
280 sort[ul]->data = fd; | 281 sort[ul]->data = fd; |