Index restore report action updates
This commit is contained in:
@@ -29,6 +29,12 @@ type RestoreReport struct {
|
||||
Satisfied []string `json:"projected_satisfied,omitempty"`
|
||||
Remaining []string `json:"projected_remaining,omitempty"`
|
||||
reportPathRel string
|
||||
actionIndices map[restoreActionKey]int
|
||||
}
|
||||
|
||||
type restoreActionKey struct {
|
||||
localRelativePath string
|
||||
remoteKey string
|
||||
}
|
||||
|
||||
type RestorePlanSummary struct {
|
||||
@@ -75,11 +81,16 @@ func newRestoreReport(current *RemoteCurrentState, plan *RestorePlan, opts Resto
|
||||
SkipSame: plan.SkipSameCount,
|
||||
Conflicts: plan.ConflictCount,
|
||||
},
|
||||
Actions: make([]RestoreReportAction, 0, len(plan.Actions)),
|
||||
Satisfied: append([]string(nil), plan.Satisfied...),
|
||||
Remaining: append([]string(nil), plan.Remaining...),
|
||||
Actions: make([]RestoreReportAction, 0, len(plan.Actions)),
|
||||
Satisfied: append([]string(nil), plan.Satisfied...),
|
||||
Remaining: append([]string(nil), plan.Remaining...),
|
||||
actionIndices: make(map[restoreActionKey]int, len(plan.Actions)),
|
||||
}
|
||||
for _, action := range plan.Actions {
|
||||
key := restoreActionKey{action.LocalRelativePath, action.RemoteKey}
|
||||
if _, exists := r.actionIndices[key]; !exists {
|
||||
r.actionIndices[key] = len(r.Actions)
|
||||
}
|
||||
r.Actions = append(r.Actions, RestoreReportAction{
|
||||
Kind: string(action.Kind),
|
||||
SourceID: action.SourceID,
|
||||
@@ -109,7 +120,7 @@ func (r *RestoreReport) markDownloaded(action RestoreAction) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
if idx := r.findAction(action); idx >= 0 {
|
||||
if idx, ok := r.actionIndices[restoreActionKey{action.LocalRelativePath, action.RemoteKey}]; ok {
|
||||
r.Actions[idx].Status = "downloaded"
|
||||
r.Actions[idx].Error = ""
|
||||
}
|
||||
@@ -120,7 +131,7 @@ func (r *RestoreReport) markFailed(action RestoreAction, err error) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
if idx := r.findAction(action); idx >= 0 {
|
||||
if idx, ok := r.actionIndices[restoreActionKey{action.LocalRelativePath, action.RemoteKey}]; ok {
|
||||
r.Actions[idx].Status = "failed"
|
||||
if err != nil {
|
||||
r.Actions[idx].Error = err.Error()
|
||||
@@ -147,18 +158,6 @@ func (r *RestoreReport) setSucceeded() {
|
||||
r.Error = ""
|
||||
}
|
||||
|
||||
func (r *RestoreReport) findAction(action RestoreAction) int {
|
||||
if r == nil {
|
||||
return -1
|
||||
}
|
||||
for i := range r.Actions {
|
||||
if r.Actions[i].LocalRelativePath == action.LocalRelativePath && r.Actions[i].RemoteKey == action.RemoteKey {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func persistRestoreReport(store artifacts.Store, cfg *config.Config, report *RestoreReport) (string, error) {
|
||||
if store == nil {
|
||||
return "", fmt.Errorf("artifact store is required")
|
||||
|
||||
Reference in New Issue
Block a user