Skip to content

Commit

Permalink
[CHANGE] Better handling error for json unmarshal when check `isResto…
Browse files Browse the repository at this point in the history
…reSingleFile`
  • Loading branch information
poyaz committed Nov 29, 2023
1 parent 4e569dc commit 3c88962
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions restic/cli/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,27 @@ func (r *Restic) isRestoreSingleFile(log logr.Logger, snapshot dto.Snapshot) (bo

stdOutLines := strings.Split(capturedStdOut, "\n")

if len(stdOutLines) == 0 {
err := fmt.Errorf("no list exist for snapshot %v", snapshot.ID)
log.Error(err, "the snapshot list is empty")
return false, err
}

err := json.Unmarshal([]byte(stdOutLines[0]), &dto.Snapshot{})
if err != nil {
return false, err
}

count := 0
for _, fileJSON := range stdOutLines {
for i := 1; i < len(stdOutLines); i++ {
if len(stdOutLines[i]) == 0 {
continue
}

node := &fileNode{}
err := json.Unmarshal([]byte(fileJSON), node)
err := json.Unmarshal([]byte(stdOutLines[i]), node)
if err != nil {
continue
return false, err
}
if node.Type == "file" {
count++
Expand Down

0 comments on commit 3c88962

Please sign in to comment.