Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-ha committed Mar 10, 2024
1 parent a73aa11 commit 030ae75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type JcpCopyState struct {
OpaqueState any
CopierType CopierType
LastUpdate time.Time
Percent float64
}

func MakeNewCopyState(progress logic.JcpProgress) JcpCopyState {
return JcpCopyState{OpaqueState: progress.OpaqueState, CopierType: BlockCopier, LastUpdate: time.Now()}
percent := float64(progress.Progress.BytesTransferred) / float64(progress.Progress.Size)
return JcpCopyState{OpaqueState: progress.OpaqueState, CopierType: BlockCopier, LastUpdate: time.Now(), Percent: percent}
}
15 changes: 14 additions & 1 deletion state/statemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func loadState(fileName string) *JcpState {
}

func (copierState *JcpState) SaveState() {
copierState.Clean()
copierState.saveState(copierState.StatePath)
}

Expand Down Expand Up @@ -78,11 +79,23 @@ func (copierState *JcpState) Clean() {

for src := range copierState.CopyStates {
for dest := range copierState.CopyStates[src] {
if copierState.CopyStates[src][dest].LastUpdate.After(time.Now().AddDate(0, 0, -ValidStateWindowInDays)) {
if copierState.CopyStates[src][dest].ShouldKeep() {
newStates[src][dest] = copierState.CopyStates[src][dest]
}
}
}

copierState.CopyStates = newStates
}

func (copyState JcpCopyState) ShouldKeep() bool {
if copyState.LastUpdate.Before(time.Now().AddDate(0, 0, -ValidStateWindowInDays)) {
return false
}

if copyState.Percent == 1 {
return false
}

return true
}

0 comments on commit 030ae75

Please sign in to comment.