Skip to content

Commit

Permalink
fix the ftp store function read the local file bug (#13108) [backport]
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
liyang1009 authored and Araq committed Jan 13, 2020
1 parent ee1563e commit 1f27a2f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/pure/asyncftpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 1f27a2f

Please sign in to comment.