Skip to content

Commit

Permalink
Wrap io errs for kodata layer (#320)
Browse files Browse the repository at this point in the history
* Wrap io errs for kodata layer

* Don't shadow hostPath
  • Loading branch information
jonjohnsonjr authored Feb 25, 2021
1 parent a6442e6 commit ee74460
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,33 +455,33 @@ func walkRecursive(tw *tar.Writer, root, chroot string) error {
})
}
if err != nil {
return err
return fmt.Errorf("filepath.Walk(%q): %w", root, err)
}
// Skip other directories.
if info.Mode().IsDir() {
return nil
}
newPath := path.Join(chroot, filepath.ToSlash(hostPath[len(root):]))

hostPath, err = filepath.EvalSymlinks(hostPath)
evalPath, err := filepath.EvalSymlinks(hostPath)
if err != nil {
return err
return fmt.Errorf("filepath.EvalSymlinks(%q): %w", hostPath, err)
}

// Chase symlinks.
info, err = os.Stat(hostPath)
info, err = os.Stat(evalPath)
if err != nil {
return err
return fmt.Errorf("os.Stat(%q): %w", evalPath, err)
}
// Skip other directories.
if info.Mode().IsDir() {
return walkRecursive(tw, hostPath, newPath)
return walkRecursive(tw, evalPath, newPath)
}

// Open the file to copy it into the tarball.
file, err := os.Open(hostPath)
file, err := os.Open(evalPath)
if err != nil {
return err
return fmt.Errorf("os.Open(%q): %w", evalPath, err)
}
defer file.Close()

Expand All @@ -495,10 +495,12 @@ func walkRecursive(tw *tar.Writer, root, chroot string) error {
// 0444, or 0666, none of which are executable.
Mode: 0555,
}); err != nil {
return err
return fmt.Errorf("tar.Writer.WriteHeader(%q): %w", newPath, err)
}
_, err = io.Copy(tw, file)
return err
if _, err := io.Copy(tw, file); err != nil {
return fmt.Errorf("io.Copy(%q, %q): %w", newPath, evalPath, err)
}
return nil
})
}

Expand Down

0 comments on commit ee74460

Please sign in to comment.