]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Fix sftp_put_file returning success on failed transfers.
authorTim Kosse <tim.kosse@filezilla-project.org>
Wed, 28 Dec 2016 14:27:47 +0000 (15:27 +0100)
committerSimon Tatham <anakin@pobox.com>
Thu, 29 Dec 2016 11:18:03 +0000 (11:18 +0000)
Due to a shadowed variable, transfer failures were not reflected in the return
code to sftp_put_file. Instead of tracking the return code, use the 'err'
variable to decide which return code to use.

psftp.c

diff --git a/psftp.c b/psftp.c
index 9c042cd22faae98058fb2fc873c665529428a351..d8c4d071f0c3b4c42be646a8aa3d481d4ee71696 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -491,7 +491,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
     struct sftp_request *req;
     uint64 offset;
     RFile *file;
     struct sftp_request *req;
     uint64 offset;
     RFile *file;
-    int ret, err, eof;
+    int ret, err = 0, eof;
     struct fxp_attrs attrs;
     long permissions;
 
     struct fxp_attrs attrs;
     long permissions;
 
@@ -651,11 +651,12 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
 
        if (!ret) {
            printf("read size of %s: %s\n", outfname, fxp_error());
 
        if (!ret) {
            printf("read size of %s: %s\n", outfname, fxp_error());
+           err = 1;
             goto cleanup;
        }
        if (!(attrs.flags & SSH_FILEXFER_ATTR_SIZE)) {
            printf("read size of %s: size was not given\n", outfname);
             goto cleanup;
        }
        if (!(attrs.flags & SSH_FILEXFER_ATTR_SIZE)) {
            printf("read size of %s: size was not given\n", outfname);
-            ret = 0;
+           err = 1;
             goto cleanup;
        }
        offset = attrs.size;
             goto cleanup;
        }
        offset = attrs.size;
@@ -674,9 +675,8 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
      * FIXME: we can use FXP_FSTAT here to get the file size, and
      * thus put up a progress bar.
      */
      * FIXME: we can use FXP_FSTAT here to get the file size, and
      * thus put up a progress bar.
      */
-    ret = 1;
     xfer = xfer_upload_init(fh, offset);
     xfer = xfer_upload_init(fh, offset);
-    err = eof = 0;
+    eof = 0;
     while ((!err && !eof) || !xfer_done(xfer)) {
        char buffer[4096];
        int len, ret;
     while ((!err && !eof) || !xfer_done(xfer)) {
        char buffer[4096];
        int len, ret;
@@ -716,7 +716,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
 
     close_rfile(file);
 
 
     close_rfile(file);
 
-    return ret;
+    return (err == 0) ? 1 : 0;
 }
 
 /* ----------------------------------------------------------------------
 }
 
 /* ----------------------------------------------------------------------