Skip to content

Commit

Permalink
fix: convert path separator to slash
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin committed May 6, 2024
1 parent 9841b99 commit 01144a7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/iac/scanners/helm/parser/parser_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,22 @@ func (p *Parser) addTarToFS(archivePath string) (fs.FS, error) {
return nil, fmt.Errorf("failed to get next entry: %w", err)
}

name := filepath.ToSlash(header.Name)

if checkExistedChart {
// Do not add archive files to FS if the chart already exists
// This can happen when the source chart is located next to an archived chart (with the `helm package` command)
// The first level folder in the archive is equal to the Chart name
if _, err := tarFS.Stat(filepath.Dir(archivePath) + "/" + filepath.Dir(header.Name)); err == nil {
if _, err := tarFS.Stat(path.Dir(archivePath) + "/" + path.Dir(name)); err == nil {
return nil, errSkipFS
}
checkExistedChart = false
}

// get the individual path and extract to the current directory
targetPath := path.Join(filepath.Dir(archivePath), filepath.Clean(header.Name))
targetPath := path.Join(path.Dir(archivePath), path.Clean(name))

link := filepath.ToSlash(header.Linkname)

switch header.Typeflag {
case tar.TypeDir:
Expand All @@ -76,12 +80,12 @@ func (p *Parser) addTarToFS(archivePath string) (fs.FS, error) {
return nil, err
}
case tar.TypeSymlink:
if filepath.IsAbs(header.Linkname) {
p.debug.Log("Symlink %s is absolute, skipping", header.Linkname)
if path.IsAbs(link) {
p.debug.Log("Symlink %s is absolute, skipping", link)
continue
}

symlinks[targetPath] = path.Join(filepath.Dir(targetPath), header.Linkname) // nolint:gosec // virtual file system is used
symlinks[targetPath] = path.Join(path.Dir(targetPath), link) // nolint:gosec // virtual file system is used
default:
return nil, fmt.Errorf("header type %q is not supported", header.Typeflag)
}
Expand Down Expand Up @@ -126,7 +130,7 @@ func copySymlink(fsys *memoryfs.FS, src, dst string) error {
}

func copyFile(fsys *memoryfs.FS, src io.Reader, dst string) error {
if err := fsys.MkdirAll(filepath.Dir(dst), fs.ModePerm); err != nil && !errors.Is(err, fs.ErrExist) {
if err := fsys.MkdirAll(path.Dir(dst), fs.ModePerm); err != nil && !errors.Is(err, fs.ErrExist) {
return fmt.Errorf("mkdir error: %w", err)
}

Expand Down

0 comments on commit 01144a7

Please sign in to comment.