From 916abed02a0bfe6ea698696ee8e16ac0e7881297 Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Wed, 12 Jul 2023 18:13:40 +0200 Subject: [PATCH] Fix file upload EOF bug --- error.go | 1 - file.go | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/error.go b/error.go index 9818db7..44ee430 100644 --- a/error.go +++ b/error.go @@ -15,7 +15,6 @@ var ( ErrLinkMustBeActive = errors.New("can not operate on link state other than active") ErrDownloadedBlockHashVerificationFailed = errors.New("the hash of the downloaded block doesn't match the original hash") ErrDraftExists = errors.New("a draft exist - usually this means a file is being uploaded at another client, or, there was a failed upload attempt") - ErrWrongEOFAssumption = errors.New("we have a problem in the assumption where EOF comes on its own") ErrCantFindActiveRevision = errors.New("can't find an active revision") ErrCantFindDraftRevision = errors.New("can't find a draft revision") ) diff --git a/file.go b/file.go index 9deb8c9..247dd09 100644 --- a/file.go +++ b/file.go @@ -403,18 +403,23 @@ func (protonDrive *ProtonDrive) uploadAndCollectBlockData(ctx context.Context, n return nil } - for i := 1; ; i++ { + shouldContinue := true + for i := 1; shouldContinue; i++ { // read at most data of size UPLOAD_BLOCK_SIZE data := make([]byte, UPLOAD_BLOCK_SIZE) // FIXME: get block size from the server config instead of hardcoding it readBytes, err := file.Read(data) + if err != nil { if err == io.EOF { - if readBytes > 0 { - return nil, 0, ErrWrongEOFAssumption + // might still have data to read! + if readBytes == 0 { + break } - break + shouldContinue = false + } else { + // all other errors + return nil, 0, err } - return nil, 0, err } data = data[:readBytes] totalFileSize += int64(readBytes)