Skip to content

Commit

Permalink
Merge pull request #1494 from 0chain/fix/save-progress
Browse files Browse the repository at this point in the history
add opt for save progress
  • Loading branch information
dabasov authored May 18, 2024
2 parents 9065d01 + 68e6d64 commit 912ef0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 17 additions & 9 deletions zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
CancelOpCtx = make(map[string]context.CancelCauseFunc)
cancelLock sync.Mutex
CurrentMode = UploadModeMedium
shouldSaveProgress = true
)

// DefaultChunkSize default chunk size for file and thumbnail
Expand Down Expand Up @@ -224,7 +225,7 @@ func CreateChunkedUpload(
opt(su)
}

if su.progressStorer == nil {
if su.progressStorer == nil && shouldSaveProgress {
su.progressStorer = createFsChunkedUploadProgress(context.Background())
}

Expand Down Expand Up @@ -352,27 +353,34 @@ func (su *ChunkedUpload) loadProgress() {
su.progress.ChunkIndex = -1

progressID := su.progressID()
if shouldSaveProgress {
progress := su.progressStorer.Load(progressID)

progress := su.progressStorer.Load(progressID)

if progress != nil {
su.progress = *progress
su.progress.ID = progressID
if progress != nil {
su.progress = *progress
su.progress.ID = progressID
}
}
}

// saveProgress save progress to ~/.zcn/upload/[progressID]
func (su *ChunkedUpload) saveProgress() {
su.progressStorer.Save(su.progress)
if su.progressStorer != nil {
su.progressStorer.Save(su.progress)
}
}

// removeProgress remove progress info once it is done
func (su *ChunkedUpload) removeProgress() {
su.progressStorer.Remove(su.progress.ID) //nolint
if su.progressStorer != nil {
su.progressStorer.Remove(su.progress.ID) //nolint
}
}

func (su *ChunkedUpload) updateProgress(chunkIndex int) {
su.progressStorer.Update(su.progress.ID, chunkIndex)
if su.progressStorer != nil {
su.progressStorer.Update(su.progress.ID, chunkIndex)
}
}

// createUploadProgress create a new UploadProgress
Expand Down
4 changes: 4 additions & 0 deletions zboxcore/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func SetShouldVerifyHash(verify bool) {
shouldVerifyHash = verify
}

func SetSaveProgress(save bool) {
shouldSaveProgress = save
}

// GetVersion - returns version string
func GetVersion() string {
return version.VERSIONSTR
Expand Down

0 comments on commit 912ef0c

Please sign in to comment.