Skip to content

Commit

Permalink
windows: handle the runtime and app is on different drives
Browse files Browse the repository at this point in the history
  • Loading branch information
fredr committed Dec 16, 2024
1 parent 4720ffc commit a2848e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 5 additions & 2 deletions pkg/dockerbuild/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,18 @@ func (h HostPath) JoinHost(p HostPath) HostPath {
return h.Join(string(p))
}
func (h HostPath) ToImage() ImagePath {
return ImagePath(string(h.ToUnix()))
}
func (h HostPath) ToUnix() HostPath {
if runtime.GOOS == "windows" {
// convert windows path with volume to a unix path, i.e c:\some\path -> /c/some/path
volume := filepath.VolumeName(string(h))
if len(volume) == 2 && volume[1] == ':' {
return ImagePath("/" + string(volume[0]) + filepath.ToSlash(string(h[2:])))
return HostPath("/" + string(volume[0]) + filepath.ToSlash(string(h[2:])))
}
}

return ImagePath(filepath.ToSlash(string(h)))
return HostPath(filepath.ToSlash(string(h)))
}
func (h HostPath) String() string { return string(h) }
func (h HostPath) Rel(target HostPath) (HostPath, error) {
Expand Down
17 changes: 10 additions & 7 deletions pkg/dockerbuild/tarcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,17 @@ func (tc *tarCopier) rewriteSymlink(desc *dirCopyDesc, path HostPath, linkTarget
// It's a link to an absolute destination.
// Determine its relative path, and see if that lives within the desc.SrcPath.
absTarget = linkTarget
relFromSrcPath, err = desc.SrcPath.Rel(absTarget)
if err != nil {
return "", err
}
// On Windows, we can only make a relative link if the source and target are on the same volume.
if runtime.GOOS != "windows" || filepath.VolumeName(desc.SrcPath.String()) == filepath.VolumeName(absTarget.String()) {
relFromSrcPath, err = desc.SrcPath.Rel(absTarget)
if err != nil {
return "", err
}

// If the relative path is local to the SrcPath, allow it.
if filepath.IsLocal(relFromSrcPath.String()) {
return desc.DstPath.JoinImage(relFromSrcPath.ToImage()), nil
// If the relative path is local to the SrcPath, allow it.
if filepath.IsLocal(relFromSrcPath.String()) {
return desc.DstPath.JoinImage(relFromSrcPath.ToImage()), nil
}
}
} else {
// We have a relative link target. Determine its absolute destination.
Expand Down

0 comments on commit a2848e9

Please sign in to comment.