diff options
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | 18 | ||
19 | RCSID("$OpenBSD: sftp.c,v 1.59 2004/11/29 07:41:24 djm Exp $"); | 19 | RCSID("$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); |