summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2004-12-11 13:37:22 +1100
committerDarren Tucker <dtucker@zip.com.au>2004-12-11 13:37:22 +1100
commit596dcfa21fba253b25020be8578efb6a1a1e30d2 (patch)
tree5fff9bb8679f9408d292bdb400f1931263b5d48f
parent56c9598e5edacbb45d155eebafb3480c6efb7382 (diff)
- fgsch@cvs.openbsd.org 2004/12/10 03:10:42
[sftp.c] - fix globbed ls for paths the same lenght as the globbed path when we have a unique matching. - fix globbed ls in case of a directory when we have a unique matching. - as a side effect, if the path does not exist error (used to silently ignore). - don't do extra do_lstat() if we only have one matching file. djm@ ok
-rw-r--r--ChangeLog11
-rw-r--r--sftp.c27
2 files changed, 26 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 49b1472bc..8c4cca4ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,15 @@
3 - markus@cvs.openbsd.org 2004/12/06 16:00:43 3 - markus@cvs.openbsd.org 2004/12/06 16:00:43
4 [bufaux.c] 4 [bufaux.c]
5 use 0x00 not \0 since buf[] is a bignum 5 use 0x00 not \0 since buf[] is a bignum
6 - fgsch@cvs.openbsd.org 2004/12/10 03:10:42
7 [sftp.c]
8 - fix globbed ls for paths the same lenght as the globbed path when
9 we have a unique matching.
10 - fix globbed ls in case of a directory when we have a unique matching.
11 - as a side effect, if the path does not exist error (used to silently
12 ignore).
13 - don't do extra do_lstat() if we only have one matching file.
14 djm@ ok
6 15
720041208 1620041208
8 - (tim) [configure.ac] Comment some non obvious platforms in the 17 - (tim) [configure.ac] Comment some non obvious platforms in the
@@ -1933,4 +1942,4 @@
1933 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 1942 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
1934 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 1943 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
1935 1944
1936$Id: ChangeLog,v 1.3601 2004/12/11 02:34:56 dtucker Exp $ 1945$Id: ChangeLog,v 1.3602 2004/12/11 02:37:22 dtucker Exp $
diff --git a/sftp.c b/sftp.c
index 2c7b546f7..9e29cb02e 100644
--- a/sftp.c
+++ b/sftp.c
@@ -16,7 +16,7 @@
16 16
17#include "includes.h" 17#include "includes.h"
18 18
19RCSID("$OpenBSD: sftp.c,v 1.59 2004/11/29 07:41:24 djm Exp $"); 19RCSID("$OpenBSD: sftp.c,v 1.60 2004/12/10 03:10:42 fgsch Exp $");
20 20
21#ifdef USE_LIBEDIT 21#ifdef USE_LIBEDIT
22#include <histedit.h> 22#include <histedit.h>
@@ -746,12 +746,14 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
746{ 746{
747 glob_t g; 747 glob_t g;
748 int i, c = 1, colspace = 0, columns = 1; 748 int i, c = 1, colspace = 0, columns = 1;
749 Attrib *a; 749 Attrib *a = NULL;
750 750
751 memset(&g, 0, sizeof(g)); 751 memset(&g, 0, sizeof(g));
752 752
753 if (remote_glob(conn, path, GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE, 753 if (remote_glob(conn, path, GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE,
754 NULL, &g)) { 754 NULL, &g) || (g.gl_pathc && !g.gl_matchc)) {
755 if (g.gl_pathc)
756 globfree(&g);
755 error("Can't ls: \"%s\" not found", path); 757 error("Can't ls: \"%s\" not found", path);
756 return (-1); 758 return (-1);
757 } 759 }
@@ -760,19 +762,21 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
760 goto out; 762 goto out;
761 763
762 /* 764 /*
763 * If the glob returns a single match, which is the same as the 765 * If the glob returns a single match and it is a directory,
764 * input glob, and it is a directory, then just list its contents 766 * then just list its contents.
765 */ 767 */
766 if (g.gl_pathc == 1 && 768 if (g.gl_matchc == 1) {
767 strncmp(path, g.gl_pathv[0], strlen(g.gl_pathv[0]) - 1) == 0) { 769 if ((a = do_lstat(conn, g.gl_pathv[0], 1)) == NULL) {
768 if ((a = do_lstat(conn, path, 1)) == NULL) {
769 globfree(&g); 770 globfree(&g);
770 return (-1); 771 return (-1);
771 } 772 }
772 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && 773 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) &&
773 S_ISDIR(a->perm)) { 774 S_ISDIR(a->perm)) {
775 int err;
776
777 err = do_ls_dir(conn, g.gl_pathv[0], strip_path, lflag);
774 globfree(&g); 778 globfree(&g);
775 return (do_ls_dir(conn, path, strip_path, lflag)); 779 return (err);
776 } 780 }
777 } 781 }
778 782
@@ -792,7 +796,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
792 colspace = width / columns; 796 colspace = width / columns;
793 } 797 }
794 798
795 for (i = 0; g.gl_pathv[i] && !interrupted; i++) { 799 for (i = 0; g.gl_pathv[i] && !interrupted; i++, a = NULL) {
796 char *fname; 800 char *fname;
797 801
798 fname = path_strip(g.gl_pathv[i], strip_path); 802 fname = path_strip(g.gl_pathv[i], strip_path);
@@ -809,7 +813,8 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
809 * that the server returns as well as the filenames. 813 * that the server returns as well as the filenames.
810 */ 814 */
811 memset(&sb, 0, sizeof(sb)); 815 memset(&sb, 0, sizeof(sb));
812 a = do_lstat(conn, g.gl_pathv[i], 1); 816 if (a == NULL)
817 a = do_lstat(conn, g.gl_pathv[i], 1);
813 if (a != NULL) 818 if (a != NULL)
814 attrib_to_stat(a, &sb); 819 attrib_to_stat(a, &sb);
815 lname = ls_file(fname, &sb, 1); 820 lname = ls_file(fname, &sb, 1);