commit 9c9e60d1c17cfe7ba0561ee4c2561b67bf9d455e from: Omar Polo date: Wed Nov 23 17:47:11 2022 UTC kamiftp: ls: accept an optional a path commit - dd647997d47ec5a9521faa59bf7628c9cab5334d commit + 9c9e60d1c17cfe7ba0561ee4c2561b67bf9d455e blob - 00fccfd538858b7555dc8d89295d97df3c354055 blob + f440e1a8a3df489a8069f6beaf66b4148d42ebcf --- kamiftp/ftp.c +++ kamiftp/ftp.c @@ -1274,27 +1274,47 @@ cmd_lpwd(int argc, const char **argv) static void cmd_ls(int argc, const char **argv) { + struct qid qid; struct np_stat st; time_t now, mtime; struct tm *tm; uint64_t off = 0; uint32_t len; - int nfid; + int nfid, miss; const char *timfmt; char fmt[FMT_SCALED_STRSIZE], tim[13], *errstr; - if (argc != 0) { - printf("ls don't take arguments (yet)\n"); + if (argc > 1) { + puts("usage: ls [path]"); return; } now = time(NULL); nfid = nextfid(); - if ((errstr = dup_fid(pwdfid, nfid)) != NULL) { - printf(".: %s\n", errstr); - free(errstr); - return; + if (argc == 0) { + if ((errstr = dup_fid(pwdfid, nfid)) != NULL) { + printf(".: %s\n", errstr); + free(errstr); + return; + } + } else { + errstr = walk_path(pwdfid, nfid, argv[0], &miss, &qid); + if (errstr != NULL) { + printf("%s: %s\n", argv[0], errstr); + free(errstr); + return; + } + if (miss) { + printf("%s: No such file or directory\n", + argv[0]); + return; + } + if (!(qid.type & QTDIR)) { + printf("%s: not a directory\n", argv[0]); + do_clunk(nfid); + return; + } } do_open(nfid, KOREAD); blob - 1d7768e8b549a3095444a6b642d15503d635358b blob + c22fcc820b2e07e26fd86cddbbfb5c72d61925e3 --- kamiftp/kamiftp.1 +++ kamiftp/kamiftp.1 @@ -116,8 +116,10 @@ or the if not given. .It Ic lpwd Print the local working directory. -.It Ic ls -List the file in the remote current working directory. +.It Ic ls Op Ar path +List the file in the remote current working directory or +.Ar path +if provided. .It Ic page Ar remote-file Download .Ar remote-file