Skip to content

Commit

Permalink
Exclude OWNERS files when pulling devfile stack
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Martin <phmartin@redhat.com>
  • Loading branch information
feloy committed May 4, 2022
1 parent 1821103 commit c377ea3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions registry-library/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func PullStackByMediaTypesFromRegistry(registry string, stack string, allowedMed
// Decompress archive.tar
archivePath := filepath.Join(destDir, "archive.tar")
if _, err := os.Stat(archivePath); err == nil {
err := decompress(destDir, archivePath)
err := decompress(destDir, archivePath, []string{"OWNERS"})
if err != nil {
return err
}
Expand All @@ -349,7 +349,7 @@ func PullStackFromRegistry(registry string, stack string, destDir string, option
}

// decompress extracts the archive file
func decompress(targetDir string, tarFile string) error {
func decompress(targetDir string, tarFile string, excludeFiles []string) error {
reader, err := os.Open(tarFile)
if err != nil {
return err
Expand All @@ -370,6 +370,9 @@ func decompress(targetDir string, tarFile string) error {
} else if err != nil {
return err
}
if isExcluded(header.Name, excludeFiles) {
continue
}

target := path.Join(targetDir, header.Name)
switch header.Typeflag {
Expand All @@ -396,6 +399,16 @@ func decompress(targetDir string, tarFile string) error {
return nil
}

func isExcluded(name string, excludeFiles []string) bool {
basename := filepath.Base(name)
for _, excludeFile := range excludeFiles {
if basename == excludeFile {
return true
}
}
return false
}

//setHeaders sets the request headers
func setHeaders(headers *http.Header, options RegistryOptions) {
t := options.Telemetry
Expand Down

0 comments on commit c377ea3

Please sign in to comment.