Skip to content

Commit

Permalink
Merge branch 'sprint-1.11' into fix/auth-ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 authored Dec 4, 2023
2 parents 408bfbe + f2d30c5 commit 6e83bac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const (
CanRenameMask = uint16(32) // 0010 0000
)

const (
emptyFileDataHash = "d41d8cd98f00b204e9800998ecf8427e"
)

// Expected success rate is calculated (NumDataShards)*100/(NumDataShards+NumParityShards)

var GetFileInfo = func(localpath string) (os.FileInfo, error) {
Expand Down Expand Up @@ -466,7 +470,6 @@ func (a *Allocation) EncryptAndUploadFileWithThumbnail(
}

func (a *Allocation) StartMultiUpload(workdir string, localPaths []string, fileNames []string, thumbnailPaths []string, encrypts []bool, chunkNumbers []int, remotePaths []string, isUpdate []bool, isWebstreaming []bool, status StatusCallback) error {
l.Logger.Debug("Initialize batch: ", BatchSize, MultiOpBatchSize)
if len(localPaths) != len(thumbnailPaths) {
return errors.New("invalid_value", "length of localpaths and thumbnailpaths must be equal")
}
Expand Down Expand Up @@ -556,6 +559,13 @@ func (a *Allocation) StartMultiUpload(workdir string, localPaths []string, fileN
Workdir: workdir,
RemotePath: fileMeta.RemotePath,
}
if fileMeta.ActualSize == 0 {
byteReader := bytes.NewReader([]byte(
emptyFileDataHash))
operationRequests[idx].FileReader = byteReader
operationRequests[idx].Opts = append(operationRequests[idx].Opts, WithActualHash(emptyFileDataHash))
operationRequests[idx].FileMeta.ActualSize = int64(len(emptyFileDataHash))
}
if isUpdate[idx] {
operationRequests[idx].OperationType = constants.FileOperationUpdate
}
Expand Down
4 changes: 3 additions & 1 deletion zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ func (su *ChunkedUpload) process() error {
su.progress.UploadLength += chunks.totalReadSize

if chunks.isFinal {
su.fileMeta.ActualHash, err = su.chunkReader.GetFileHash()
if su.fileMeta.ActualHash == "" {
su.fileMeta.ActualHash, err = su.chunkReader.GetFileHash()
}
if err != nil {
if su.statusCallback != nil {
su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err)
Expand Down
6 changes: 6 additions & 0 deletions zboxcore/sdk/chunked_upload_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ func WithEncryptedPoint(point string) ChunkedUploadOption {
su.encryptedKeyPoint = point
}
}

func WithActualHash(hash string) ChunkedUploadOption {
return func(su *ChunkedUpload) {
su.fileMeta.ActualHash = hash
}
}
7 changes: 7 additions & 0 deletions zboxcore/sdk/downloadworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ func (req *DownloadRequest) processDownload(ctx context.Context) {
op = opThumbnailDownload
}
fRef := req.fRef
if fRef != nil && fRef.ActualFileHash == emptyFileDataHash {
if req.statusCallback != nil {
req.statusCallback.Completed(
req.allocationID, remotePathCB, fRef.Name, "", len(emptyFileDataHash), op)
}
return
}
size, chunksPerShard, blocksPerShard := req.size, req.chunksPerShard, req.blocksPerShard

logger.Logger.Info(
Expand Down

0 comments on commit 6e83bac

Please sign in to comment.