Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: host builder nonregular file support #2156

Merged
merged 12 commits into from
Feb 20, 2024
22 changes: 11 additions & 11 deletions pkg/oci/containerize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"os"
slashpath "path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -136,6 +135,8 @@ func newDataTarball(source, target string, ignored []string, verbose bool) error
tw := tar.NewWriter(gw)
defer tw.Close()

baseDir := "/func"

return filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -150,27 +151,26 @@ func newDataTarball(source, target string, ignored []string, verbose bool) error
}
}

header, err := tar.FileInfoHeader(info, info.Name())
if err != nil {
return err
var link string
if info.Mode()&os.ModeSymlink == os.ModeSymlink {
if link, err = os.Readlink(path); err != nil {
matejvasek marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}

relPath, err := filepath.Rel(source, path)
header, err := tar.FileInfoHeader(info, link)
if err != nil {
return err
}

header.Name = slashpath.Join("/func", filepath.ToSlash(relPath))
// TODO: should we set file timestamps to the build start time of cfg.t?
// header.ModTime = timestampArgument

if err := tw.WriteHeader(header); err != nil {
header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source))
matejvasek marked this conversation as resolved.
Show resolved Hide resolved
if err = tw.WriteHeader(header); err != nil {
return err
}
if verbose {
fmt.Printf("→ %v \n", header.Name)
}
if info.IsDir() {
if !info.Mode().IsRegular() { //nothing more to do for non-regular
return nil
}

Expand Down
Loading