ftpd/ls: show directories first

Old TODO finally done

function                                             old     new   delta
ls_main                                              548     568     +20
packed_usage                                       31116   31097     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-01-25 04:52:45 +01:00
parent 8a2657cbf5
commit b13b618335
2 changed files with 11 additions and 11 deletions

View File

@ -1045,7 +1045,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
int ls_main(int argc UNUSED_PARAM, char **argv) int ls_main(int argc UNUSED_PARAM, char **argv)
{ { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */
struct dnode **dnd; struct dnode **dnd;
struct dnode **dnf; struct dnode **dnf;
struct dnode **dnp; struct dnode **dnp;
@ -1175,6 +1175,11 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
if (!(option_mask32 & (OPT_l|OPT_1|OPT_x|OPT_C))) if (!(option_mask32 & (OPT_l|OPT_1|OPT_x|OPT_C)))
option_mask32 |= (isatty(STDOUT_FILENO) ? OPT_C : OPT_1); option_mask32 |= (isatty(STDOUT_FILENO) ? OPT_C : OPT_1);
if (ENABLE_FTPD && applet_name[0] == 'f') {
/* ftpd secret backdoor. dirs first are much nicer */
option_mask32 |= OPT_dirs_first;
}
argv += optind; argv += optind;
if (!argv[0]) if (!argv[0])
*--argv = (char*)"."; *--argv = (char*)".";

View File

@ -61,12 +61,12 @@
//usage: "Can be run from tcpsvd:\n" //usage: "Can be run from tcpsvd:\n"
//usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n" //usage: " tcpsvd -vE 0.0.0.0 21 ftpd /files/to/serve\n"
//usage: "\n -w Allow upload" //usage: "\n -w Allow upload"
//usage: "\n -v Log errors to stderr. -vv: verbose log"
//usage: "\n -S Log errors to syslog. -SS: verbose log"
//usage: IF_FEATURE_FTPD_AUTHENTICATION( //usage: IF_FEATURE_FTPD_AUTHENTICATION(
//usage: "\n -a USER Enable 'anonymous' login and map it to USER" //usage: "\n -a USER Enable 'anonymous' login and map it to USER"
//usage: ) //usage: )
//usage: "\n -t,-T Idle and absolute timeouts" //usage: "\n -v Log errors to stderr. -vv: verbose log"
//usage: "\n -S Log errors to syslog. -SS: verbose log"
//usage: "\n -t,-T N Idle and absolute timeout"
#include "libbb.h" #include "libbb.h"
#include "common_bufsiz.h" #include "common_bufsiz.h"
@ -701,7 +701,7 @@ popen_ls(const char *opt)
dup(STDOUT_FILENO); /* copy will become STDIN_FILENO */ dup(STDOUT_FILENO); /* copy will become STDIN_FILENO */
#if BB_MMU #if BB_MMU
/* memset(&G, 0, sizeof(G)); - ls_main does it */ /* memset(&G, 0, sizeof(G)); - ls_main does it */
exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv)); exit(ls_main(/*argc_unused*/ 0, (char**) argv));
#else #else
cur_fd = xopen(".", O_RDONLY | O_DIRECTORY); cur_fd = xopen(".", O_RDONLY | O_DIRECTORY);
/* On NOMMU, we want to execute a child - copy of ourself /* On NOMMU, we want to execute a child - copy of ourself
@ -1152,11 +1152,7 @@ enum {
}; };
int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#if !BB_MMU
int ftpd_main(int argc, char **argv)
#else
int ftpd_main(int argc UNUSED_PARAM, char **argv) int ftpd_main(int argc UNUSED_PARAM, char **argv)
#endif
{ {
#if ENABLE_FEATURE_FTPD_AUTHENTICATION #if ENABLE_FEATURE_FTPD_AUTHENTICATION
struct passwd *pw = NULL; struct passwd *pw = NULL;
@ -1184,11 +1180,10 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
&G.verbose, &verbose_S); &G.verbose, &verbose_S);
if (opts & (OPT_l|OPT_1)) { if (opts & (OPT_l|OPT_1)) {
/* Our secret backdoor to ls */ /* Our secret backdoor to ls */
/* TODO: pass --group-directories-first? */
if (fchdir(3) != 0) if (fchdir(3) != 0)
_exit(127); _exit(127);
/* memset(&G, 0, sizeof(G)); - ls_main does it */ /* memset(&G, 0, sizeof(G)); - ls_main does it */
return ls_main(argc, argv); return ls_main(/*argc_unused*/ 0, argv);
} }
#endif #endif
if (G.verbose < verbose_S) if (G.verbose < verbose_S)