Skip to content

Commit 5a93bc7

Browse files
committed
SFTPStream: fix error handling in fastGet/fastPut
1 parent 1221fe6 commit 5a93bc7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/sftp.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,11 +971,17 @@ function fastXfer(src, dst, srcPath, dstPath, opts, cb) {
971971
pdst = 0,
972972
reads = 0,
973973
total = 0,
974+
hadError = false,
974975
srcHandle,
975976
dstHandle,
976977
readbuf = new Buffer(chunkSize * concurrency);
977978

978979
function onerror(err) {
980+
if (hadError)
981+
return;
982+
983+
hadError = true;
984+
979985
var left = 0,
980986
cbfinal;
981987

@@ -984,13 +990,13 @@ function fastXfer(src, dst, srcPath, dstPath, opts, cb) {
984990
if (--left === 0)
985991
cb(err);
986992
};
987-
if (srcHandle)
993+
if (srcHandle && (src === fs || src.writable))
988994
++left;
989-
if (dstHandle)
995+
if (dstHandle && (dst === fs || dst.writable))
990996
++left;
991-
if (srcHandle)
997+
if (srcHandle && (src === fs || src.writable))
992998
src.close(srcHandle, cbfinal);
993-
if (dstHandle)
999+
if (dstHandle && (dst === fs || dst.writable))
9941000
dst.close(dstHandle, cbfinal);
9951001
} else
9961002
cb(err);

0 commit comments

Comments
 (0)