Skip to content

Commit

Permalink
add back in correct path support for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Feb 14, 2024
1 parent be43ac3 commit ed15d98
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/oci/containerize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
slashpath "path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -136,13 +137,12 @@ 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
}

// Skip files explicitly ignored
for _, v := range ignored {
if info.Name() == v {
if info.IsDir() {
Expand All @@ -152,9 +152,10 @@ func newDataTarball(source, target string, ignored []string, verbose bool) error
}
}

var link string
// Error if links exist which reach outside of the function root
if info.Mode()&os.ModeSymlink == os.ModeSymlink {
if link, err = os.Readlink(path); err != nil {
link, err := os.Readlink(path)
if err != nil {
return err
}
ok, err := isWithin(source, link)
Expand All @@ -165,13 +166,17 @@ func newDataTarball(source, target string, ignored []string, verbose bool) error
}
}

header, err := tar.FileInfoHeader(info, link)
header, err := tar.FileInfoHeader(info, info.Name())
if err != nil {
return err
}

header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source))
if err = tw.WriteHeader(header); err != nil {
relPath, err := filepath.Rel(source, path)
if err != nil {
return err
}
header.Name = slashpath.Join("/func", filepath.ToSlash(relPath))
if err := tw.WriteHeader(header); err != nil {
return err
}
if verbose {
Expand Down

0 comments on commit ed15d98

Please sign in to comment.