Skip to content

Commit

Permalink
Fix error on restore if cache key is not present (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham149 authored Feb 4, 2021
1 parent 50599aa commit 3c475b7
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions cache/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,15 @@ func (r restorer) Restore(dsts []string) error {
namespace = filepath.ToSlash(filepath.Clean(r.namespace))
)

if r.failIfKeyNotPresent {
prefix := filepath.Join(namespace, key)
exists, err := r.s.Exists(prefix)

if err != nil {
return fmt.Errorf("failed to find key: %s with err: %v", prefix, err)
}

if !exists {
return fmt.Errorf("key %s does not exist", prefix)
}
}

if len(dsts) == 0 {
prefix := filepath.Join(namespace, key)
entries, err := r.s.List(prefix)

if err == nil {
if r.failIfKeyNotPresent && len(entries) == 0 {
return fmt.Errorf("key %s does not exist", prefix)
}

for _, e := range entries {
dsts = append(dsts, strings.TrimPrefix(e.Path, prefix+"/"))
}
Expand Down

0 comments on commit 3c475b7

Please sign in to comment.