mirror of
https://github.com/henrybear327/Proton-API-Bridge.git
synced 2026-05-24 23:06:06 -04:00
Fix file upload EOF bug
This commit is contained in:
1
error.go
1
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")
|
||||
)
|
||||
|
||||
15
file.go
15
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)
|
||||
|
||||
Reference in New Issue
Block a user