From ec7519c5d845365a3657b0928fd70cae64a95ee4 Mon Sep 17 00:00:00 2001 From: Denis Ollier Date: Wed, 5 Nov 2025 21:32:58 +0100 Subject: [PATCH] Don't skip symlinks during local source upload Signed-off-by: Denis Ollier --- docs/shp_build_upload.md | 4 ++-- pkg/shp/cmd/build/upload.go | 4 ++-- pkg/shp/streamer/tar.go | 2 +- pkg/shp/streamer/util.go | 32 ++++++++++++++++++++++++-------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/docs/shp_build_upload.md b/docs/shp_build_upload.md index ae8967cbf..0eb741dcf 100644 --- a/docs/shp_build_upload.md +++ b/docs/shp_build_upload.md @@ -17,8 +17,8 @@ In case a source bundle image is defined, the bundling feature is used, which wi source code into a bundle container and upload it to the specified container registry. Instead of executing using Git in the source step, it will use the container registry to obtain the source code. - $ shp buildrun upload - $ shp buildrun upload /path/to/repository + $ shp build upload + $ shp build upload /path/to/repository ``` diff --git a/pkg/shp/cmd/build/upload.go b/pkg/shp/cmd/build/upload.go index 6c80fffcb..6a5df0319 100644 --- a/pkg/shp/cmd/build/upload.go +++ b/pkg/shp/cmd/build/upload.go @@ -56,8 +56,8 @@ In case a source bundle image is defined, the bundling feature is used, which wi source code into a bundle container and upload it to the specified container registry. Instead of executing using Git in the source step, it will use the container registry to obtain the source code. - $ shp buildrun upload - $ shp buildrun upload /path/to/repository + $ shp build upload + $ shp build upload /path/to/repository ` // targetBaseDir directory where data will be uploaded. diff --git a/pkg/shp/streamer/tar.go b/pkg/shp/streamer/tar.go index e2255f7c7..f50df07c2 100644 --- a/pkg/shp/streamer/tar.go +++ b/pkg/shp/streamer/tar.go @@ -21,7 +21,7 @@ type Tar struct { // skipPath inspect each path and makes sure it skips files the tar helper can't handle. func (t *Tar) skipPath(fpath string, stat fs.FileInfo) bool { - if !stat.Mode().IsRegular() { + if !stat.Mode().IsRegular() && !(stat.Mode()&fs.ModeSymlink != 0) { return true } if strings.HasPrefix(fpath, path.Join(t.src, ".git")) { diff --git a/pkg/shp/streamer/util.go b/pkg/shp/streamer/util.go index 4fa42b724..3c0fdc94f 100644 --- a/pkg/shp/streamer/util.go +++ b/pkg/shp/streamer/util.go @@ -28,17 +28,33 @@ func writeFileToTar(tw *tar.Writer, src, fpath string, stat fs.FileInfo) error { } header.Name = trimPrefix(src, fpath) - if err := tw.WriteHeader(header); err != nil { - return err + + // Symlink + if stat.Mode()&os.ModeSymlink != 0 { + target, err := os.Readlink(fpath) + if err != nil { + return err + } + + header.Linkname = target } - // #nosec G304 intentionally opening file from variable - f, err := os.Open(fpath) - if err != nil { + if err := tw.WriteHeader(header); err != nil { return err } - if _, err := io.Copy(tw, f); err != nil { - return err + + // Copy regular file content + if stat.Mode().IsRegular() { + // #nosec G304 intentionally opening file from variable + f, err := os.Open(fpath) + if err != nil { + return err + } + if _, err := io.Copy(tw, f); err != nil { + return err + } + return f.Close() } - return f.Close() + + return nil }