mirror of
https://github.com/ko-build/ko.git
synced 2026-06-18 20:14:08 +02:00
Wrap io errs for kodata layer (#320)
* Wrap io errs for kodata layer * Don't shadow hostPath
This commit is contained in:
+13
-11
@@ -455,7 +455,7 @@ 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() {
|
||||
@@ -463,25 +463,25 @@ func walkRecursive(tw *tar.Writer, root, chroot string) error {
|
||||
}
|
||||
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()
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user