mirror of
https://github.com/ko-build/ko.git
synced 2026-04-02 10:22:02 +02:00
fix: handle missing kodata directory in tarKoData
filepath.EvalSymlinks fails when the kodata directory does not exist. Guard the call with os.Stat so that the non-existent case falls through to walkRecursive, which already silently no-ops for missing roots via filepath.Walk semantics. Fixes test failures in TestGoBuildNoKoData, TestGoBuildConsistentMediaTypes, and TestDebugger.
This commit is contained in:
@@ -861,13 +861,19 @@ func (g *gobuild) tarKoData(ref reference, platform *v1.Platform) (*bytes.Buffer
|
||||
|
||||
// Resolve the canonical absolute path of the kodata root so that symlink
|
||||
// targets resolved by filepath.EvalSymlinks can be compared consistently.
|
||||
resolvedRoot, err := filepath.EvalSymlinks(root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("filepath.EvalSymlinks(%q): %w", root, err)
|
||||
}
|
||||
absKodataRoot, err := filepath.Abs(resolvedRoot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("filepath.Abs(%q): %w", resolvedRoot, err)
|
||||
// If the kodata directory does not exist, walkRecursive handles that
|
||||
// gracefully (filepath.Walk skips missing roots), so we fall back to the
|
||||
// raw path as the boundary — no traversal is possible without a root.
|
||||
absKodataRoot := root
|
||||
if _, statErr := os.Stat(root); statErr == nil {
|
||||
resolvedRoot, err := filepath.EvalSymlinks(root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("filepath.EvalSymlinks(%q): %w", root, err)
|
||||
}
|
||||
absKodataRoot, err = filepath.Abs(resolvedRoot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("filepath.Abs(%q): %w", resolvedRoot, err)
|
||||
}
|
||||
}
|
||||
return buf, walkRecursive(tw, root, chroot, absKodataRoot, creationTime, platform)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user