openssh/openssh-4.5p1-sftp-drain-acks.patch
Tomáš Mráz f370730d3b - fix sftp client problems on write error (#247802)
- allow disabling autocreation of server keys (#235466)
2007-08-09 18:33:41 +00:00

71 lines
2.0 KiB
Diff

diff -up openssh-4.5p1/sftp-client.c.drain-acks openssh-4.5p1/sftp-client.c
--- openssh-4.5p1/sftp-client.c.drain-acks 2006-10-23 19:03:02.000000000 +0200
+++ openssh-4.5p1/sftp-client.c 2007-08-07 17:46:16.000000000 +0200
@@ -992,7 +992,8 @@ int
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
int pflag)
{
- int local_fd, status;
+ int local_fd;
+ int status = SSH2_FX_OK;
u_int handle_len, id, type;
u_int64_t offset;
char *handle, *data;
@@ -1074,7 +1075,7 @@ do_upload(struct sftp_conn *conn, char *
* Simulate an EOF on interrupt, allowing ACKs from the
* server to drain.
*/
- if (interrupted)
+ if (interrupted || status != SSH2_FX_OK)
len = 0;
else do
len = read(local_fd, data, conn->transfer_buflen);
@@ -1131,17 +1132,6 @@ do_upload(struct sftp_conn *conn, char *
fatal("Can't find request for ID %u", r_id);
TAILQ_REMOVE(&acks, ack, tq);
- if (status != SSH2_FX_OK) {
- error("Couldn't write to remote file \"%s\": %s",
- remote_path, fx2txt(status));
- if (showprogress)
- stop_progress_meter();
- do_close(conn, handle, handle_len);
- close(local_fd);
- xfree(data);
- xfree(ack);
- goto done;
- }
debug3("In write loop, ack for %u %u bytes at %llu",
ack->id, ack->len, (unsigned long long)ack->offset);
++ackid;
@@ -1153,21 +1143,25 @@ do_upload(struct sftp_conn *conn, char *
stop_progress_meter();
xfree(data);
+ if (status != SSH2_FX_OK) {
+ error("Couldn't write to remote file \"%s\": %s",
+ remote_path, fx2txt(status));
+ status = -1;
+ }
+
if (close(local_fd) == -1) {
error("Couldn't close local file \"%s\": %s", local_path,
strerror(errno));
- do_close(conn, handle, handle_len);
status = -1;
- goto done;
}
/* Override umask and utimes if asked */
if (pflag)
do_fsetstat(conn, handle, handle_len, &a);
- status = do_close(conn, handle, handle_len);
+ if (do_close(conn, handle, handle_len) != SSH2_FX_OK)
+ status = -1;
-done:
xfree(handle);
buffer_free(&msg);
return(status);