Skip to content

Commit

Permalink
feedback updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Jul 26, 2024
1 parent c589b15 commit bcd4adf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
1 change: 0 additions & 1 deletion pkg/combustion/combustion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type Combustion struct {
RPMResolver rpmResolver
RPMRepoCreator rpmRepoCreator
Registry embeddedRegistry
CacheDir string
}

// Configure iterates over all separate Combustion components and configures them independently.
Expand Down
22 changes: 2 additions & 20 deletions pkg/combustion/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package combustion

import (
_ "embed"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -239,12 +238,7 @@ func populateRegistry(ctx *image.Context, images []string) error {
imageCacheLocation := filepath.Join(imageCacheDir, convertedImageName)
imageTarDest := filepath.Join(registryArtefactsPath(ctx), convertedImageName)

exists, err := imageExists(imageCacheLocation)
if err != nil {
return fmt.Errorf("checking if image already cached: %w", err)
}

if exists {
if fileio.FileExists(imageCacheLocation) {
if err = fileio.CopyFile(imageCacheLocation, imageTarDest, fileio.ExecutablePerms); err != nil {
return fmt.Errorf("copying cached container image: %w", err)
}
Expand All @@ -257,7 +251,7 @@ func populateRegistry(ctx *image.Context, images []string) error {
return fmt.Errorf("generating registry store tarball: %w", err)
}

if err = fileio.CopyFile(imageTarDest, imageCacheLocation, fileio.ExecutablePerms); err != nil {
if err = fileio.CopyFile(imageTarDest, imageCacheLocation, fileio.NonExecutablePerms); err != nil {
return fmt.Errorf("copying container image to cache: %w", err)
}
}
Expand All @@ -268,15 +262,3 @@ func populateRegistry(ctx *image.Context, images []string) error {

return nil
}

func imageExists(imagePath string) (bool, error) {
if _, err := os.Stat(imagePath); err != nil {
if errors.Is(err, os.ErrNotExist) {
return false, nil
}

return false, fmt.Errorf("looking for cached image: %w", err)
}

return true, nil
}
13 changes: 13 additions & 0 deletions pkg/fileio/file_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,16 @@ func createFileWithPerms(dest string, perms os.FileMode) (*os.File, error) {

return file, nil
}

func FileExists(filePath string) bool {
if _, err := os.Stat(filePath); err != nil {
if errors.Is(err, os.ErrNotExist) {
return false
}

zap.S().Warnf("Searching for file at (%s) failed: %s", filePath, err)
return false
}

return true
}

0 comments on commit bcd4adf

Please sign in to comment.