version 1.144, 2013/05/16 09:08:41 |
version 1.145, 2013/05/17 00:13:14 |
|
|
/* XXX: quoting - rip quoting code from ftp? */ |
/* XXX: quoting - rip quoting code from ftp? */ |
snprintf(buf, len, _PATH_LS " %s", args); |
snprintf(buf, len, _PATH_LS " %s", args); |
local_do_shell(buf); |
local_do_shell(buf); |
xfree(buf); |
free(buf); |
} |
} |
} |
} |
|
|
|
|
/* Derelativise */ |
/* Derelativise */ |
if (p && p[0] != '/') { |
if (p && p[0] != '/') { |
abs_str = path_append(pwd, p); |
abs_str = path_append(pwd, p); |
xfree(p); |
free(p); |
return(abs_str); |
return(abs_str); |
} else |
} else |
return(p); |
return(p); |
|
|
tmp = xstrdup(g.gl_pathv[i]); |
tmp = xstrdup(g.gl_pathv[i]); |
if ((filename = basename(tmp)) == NULL) { |
if ((filename = basename(tmp)) == NULL) { |
error("basename %s: %s", tmp, strerror(errno)); |
error("basename %s: %s", tmp, strerror(errno)); |
xfree(tmp); |
free(tmp); |
err = -1; |
err = -1; |
goto out; |
goto out; |
} |
} |
|
|
} else { |
} else { |
abs_dst = xstrdup(filename); |
abs_dst = xstrdup(filename); |
} |
} |
xfree(tmp); |
free(tmp); |
|
|
if (!quiet) |
if (!quiet) |
printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst); |
printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst); |
|
|
pflag || global_pflag) == -1) |
pflag || global_pflag) == -1) |
err = -1; |
err = -1; |
} |
} |
xfree(abs_dst); |
free(abs_dst); |
abs_dst = NULL; |
abs_dst = NULL; |
} |
} |
|
|
out: |
out: |
xfree(abs_src); |
free(abs_src); |
globfree(&g); |
globfree(&g); |
return(err); |
return(err); |
} |
} |
|
|
tmp = xstrdup(g.gl_pathv[i]); |
tmp = xstrdup(g.gl_pathv[i]); |
if ((filename = basename(tmp)) == NULL) { |
if ((filename = basename(tmp)) == NULL) { |
error("basename %s: %s", tmp, strerror(errno)); |
error("basename %s: %s", tmp, strerror(errno)); |
xfree(tmp); |
free(tmp); |
err = -1; |
err = -1; |
goto out; |
goto out; |
} |
} |
|
|
} else { |
} else { |
abs_dst = make_absolute(xstrdup(filename), pwd); |
abs_dst = make_absolute(xstrdup(filename), pwd); |
} |
} |
xfree(tmp); |
free(tmp); |
|
|
if (!quiet) |
if (!quiet) |
printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst); |
printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst); |
|
|
} |
} |
|
|
out: |
out: |
if (abs_dst) |
free(abs_dst); |
xfree(abs_dst); |
free(tmp_dst); |
if (tmp_dst) |
|
xfree(tmp_dst); |
|
globfree(&g); |
globfree(&g); |
return(err); |
return(err); |
} |
} |
|
|
/* Add any subpath that also needs to be counted */ |
/* Add any subpath that also needs to be counted */ |
tmp = path_strip(path, strip_path); |
tmp = path_strip(path, strip_path); |
m += strlen(tmp); |
m += strlen(tmp); |
xfree(tmp); |
free(tmp); |
|
|
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1) |
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1) |
width = ws.ws_col; |
width = ws.ws_col; |
|
|
|
|
tmp = path_append(path, d[n]->filename); |
tmp = path_append(path, d[n]->filename); |
fname = path_strip(tmp, strip_path); |
fname = path_strip(tmp, strip_path); |
xfree(tmp); |
free(tmp); |
|
|
if (lflag & LS_LONG_VIEW) { |
if (lflag & LS_LONG_VIEW) { |
if (lflag & (LS_NUMERIC_VIEW|LS_SI_UNITS)) { |
if (lflag & (LS_NUMERIC_VIEW|LS_SI_UNITS)) { |
|
|
lname = ls_file(fname, &sb, 1, |
lname = ls_file(fname, &sb, 1, |
(lflag & LS_SI_UNITS)); |
(lflag & LS_SI_UNITS)); |
printf("%s\n", lname); |
printf("%s\n", lname); |
xfree(lname); |
free(lname); |
} else |
} else |
printf("%s\n", d[n]->longname); |
printf("%s\n", d[n]->longname); |
} else { |
} else { |
|
|
c++; |
c++; |
} |
} |
|
|
xfree(fname); |
free(fname); |
} |
} |
|
|
if (!(lflag & LS_LONG_VIEW) && (c != 1)) |
if (!(lflag & LS_LONG_VIEW) && (c != 1)) |
|
|
lname = ls_file(fname, g.gl_statv[i], 1, |
lname = ls_file(fname, g.gl_statv[i], 1, |
(lflag & LS_SI_UNITS)); |
(lflag & LS_SI_UNITS)); |
printf("%s\n", lname); |
printf("%s\n", lname); |
xfree(lname); |
free(lname); |
} else { |
} else { |
printf("%-*s", colspace, fname); |
printf("%-*s", colspace, fname); |
if (c >= columns) { |
if (c >= columns) { |
|
|
} else |
} else |
c++; |
c++; |
} |
} |
xfree(fname); |
free(fname); |
} |
} |
|
|
if (!(lflag & LS_LONG_VIEW) && (c != 1)) |
if (!(lflag & LS_LONG_VIEW) && (c != 1)) |
|
|
break; |
break; |
} |
} |
if ((aa = do_stat(conn, tmp, 0)) == NULL) { |
if ((aa = do_stat(conn, tmp, 0)) == NULL) { |
xfree(tmp); |
free(tmp); |
err = 1; |
err = 1; |
break; |
break; |
} |
} |
if (!(aa->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) { |
if (!(aa->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) { |
error("Can't change directory: Can't check target"); |
error("Can't change directory: Can't check target"); |
xfree(tmp); |
free(tmp); |
err = 1; |
err = 1; |
break; |
break; |
} |
} |
if (!S_ISDIR(aa->perm)) { |
if (!S_ISDIR(aa->perm)) { |
error("Can't change directory: \"%s\" is not " |
error("Can't change directory: \"%s\" is not " |
"a directory", tmp); |
"a directory", tmp); |
xfree(tmp); |
free(tmp); |
err = 1; |
err = 1; |
break; |
break; |
} |
} |
xfree(*pwd); |
free(*pwd); |
*pwd = tmp; |
*pwd = tmp; |
break; |
break; |
case I_LS: |
case I_LS: |
|
|
|
|
if (g.gl_pathc) |
if (g.gl_pathc) |
globfree(&g); |
globfree(&g); |
if (path1) |
free(path1); |
xfree(path1); |
free(path2); |
if (path2) |
|
xfree(path2); |
|
|
|
/* If an unignored error occurs in batch mode we should abort. */ |
/* If an unignored error occurs in batch mode we should abort. */ |
if (err_abort && err != 0) |
if (err_abort && err != 0) |
|
|
complete_display(list, 0); |
complete_display(list, 0); |
|
|
for (y = 0; list[y] != NULL; y++) |
for (y = 0; list[y] != NULL; y++) |
xfree(list[y]); |
free(list[y]); |
xfree(list); |
free(list); |
return count; |
return count; |
} |
} |
|
|
|
|
list[count] = NULL; |
list[count] = NULL; |
|
|
if (count == 0) { |
if (count == 0) { |
xfree(list); |
free(list); |
return 0; |
return 0; |
} |
} |
|
|
|
|
complete_display(list, 0); |
complete_display(list, 0); |
|
|
for (y = 0; list[y]; y++) |
for (y = 0; list[y]; y++) |
xfree(list[y]); |
free(list[y]); |
xfree(list); |
free(list); |
|
|
if (tmp != NULL) { |
if (tmp != NULL) { |
tmplen = strlen(tmp); |
tmplen = strlen(tmp); |
|
|
if (y > 0 && el_insertstr(el, argterm) == -1) |
if (y > 0 && el_insertstr(el, argterm) == -1) |
fatal("el_insertstr failed."); |
fatal("el_insertstr failed."); |
} |
} |
xfree(tmp); |
free(tmp); |
} |
} |
|
|
return count; |
return count; |
|
|
if (tmp[tmplen] == '/') |
if (tmp[tmplen] == '/') |
pwdlen = tmplen + 1; /* track last seen '/' */ |
pwdlen = tmplen + 1; /* track last seen '/' */ |
} |
} |
xfree(tmp); |
free(tmp); |
|
|
if (g.gl_matchc == 0) |
if (g.gl_matchc == 0) |
goto out; |
goto out; |
|
|
|
|
tmp2 = complete_ambiguous(file, g.gl_pathv, g.gl_matchc); |
tmp2 = complete_ambiguous(file, g.gl_pathv, g.gl_matchc); |
tmp = path_strip(tmp2, isabs ? NULL : remote_path); |
tmp = path_strip(tmp2, isabs ? NULL : remote_path); |
xfree(tmp2); |
free(tmp2); |
|
|
if (tmp == NULL) |
if (tmp == NULL) |
goto out; |
goto out; |
|
|
if (i > 0 && el_insertstr(el, ins) == -1) |
if (i > 0 && el_insertstr(el, ins) == -1) |
fatal("el_insertstr failed."); |
fatal("el_insertstr failed."); |
} |
} |
xfree(tmp); |
free(tmp); |
|
|
out: |
out: |
globfree(&g); |
globfree(&g); |
|
|
memcpy(line, lf->buffer, cursor); |
memcpy(line, lf->buffer, cursor); |
line[cursor] = '\0'; |
line[cursor] = '\0'; |
argv = makeargv(line, &carg, 1, "e, &terminated); |
argv = makeargv(line, &carg, 1, "e, &terminated); |
xfree(line); |
free(line); |
|
|
/* Get all the arguments on the line */ |
/* Get all the arguments on the line */ |
len = lf->lastchar - lf->buffer; |
len = lf->lastchar - lf->buffer; |
|
|
/* Ensure cursor is at EOL or a argument boundary */ |
/* Ensure cursor is at EOL or a argument boundary */ |
if (line[cursor] != ' ' && line[cursor] != '\0' && |
if (line[cursor] != ' ' && line[cursor] != '\0' && |
line[cursor] != '\n') { |
line[cursor] != '\n') { |
xfree(line); |
free(line); |
return ret; |
return ret; |
} |
} |
|
|
|
|
ret = CC_REDISPLAY; |
ret = CC_REDISPLAY; |
} |
} |
|
|
xfree(line); |
free(line); |
return ret; |
return ret; |
} |
} |
|
|
|
|
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); |
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); |
if (parse_dispatch_command(conn, cmd, |
if (parse_dispatch_command(conn, cmd, |
&remote_path, 1) != 0) { |
&remote_path, 1) != 0) { |
xfree(dir); |
free(dir); |
xfree(remote_path); |
free(remote_path); |
xfree(conn); |
free(conn); |
return (-1); |
return (-1); |
} |
} |
} else { |
} else { |
|
|
|
|
err = parse_dispatch_command(conn, cmd, |
err = parse_dispatch_command(conn, cmd, |
&remote_path, 1); |
&remote_path, 1); |
xfree(dir); |
free(dir); |
xfree(remote_path); |
free(remote_path); |
xfree(conn); |
free(conn); |
return (err); |
return (err); |
} |
} |
xfree(dir); |
free(dir); |
} |
} |
|
|
setlinebuf(stdout); |
setlinebuf(stdout); |
|
|
if (err != 0) |
if (err != 0) |
break; |
break; |
} |
} |
xfree(remote_path); |
free(remote_path); |
xfree(conn); |
free(conn); |
|
|
if (el != NULL) |
if (el != NULL) |
el_end(el); |
el_end(el); |