From 1f27a2f8ab696bbbfcf4d8f0bf2748dfc1cc86ad Mon Sep 17 00:00:00 2001 From: perter lee Date: Mon, 13 Jan 2020 17:16:19 +0800 Subject: [PATCH] fix the ftp store function read the local file bug (#13108) [backport] * Update asyncftpclient.nim When use newStringOfCap function not have assign memory for the string data,so if use this address the fault is rasise. * complelete the bugfix --- lib/pure/asyncftpclient.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pure/asyncftpclient.nim b/lib/pure/asyncftpclient.nim index ce31542b160a..c1cfc6cc648b 100644 --- a/lib/pure/asyncftpclient.nim +++ b/lib/pure/asyncftpclient.nim @@ -351,15 +351,13 @@ proc doUpload(ftp: AsyncFtpClient, file: File, assert ftp.dsockConnected let total = file.getFileSize() - var data = newStringOfCap(4000) + var data = newString(4000) var progress = 0 var progressInSecond = 0 var countdownFut = sleepAsync(1000) var sendFut: Future[void] = nil while ftp.dsockConnected: - if sendFut == nil or sendFut.finished: - progress.inc(data.len) - progressInSecond.inc(data.len) + if sendFut == nil or sendFut.finished: # TODO: Async file reading. let len = file.readBuffer(addr(data[0]), 4000) setLen(data, len) @@ -370,6 +368,8 @@ proc doUpload(ftp: AsyncFtpClient, file: File, assertReply(await(ftp.expectReply()), "226") else: + progress.inc(len) + progressInSecond.inc(len) sendFut = ftp.dsock.send(data) if countdownFut.finished: