Skip to content

Commit

Permalink
Merge pull request nephio-project#82 from nokia/binary-file-error-msg
Browse files Browse the repository at this point in the history
Return an error if 'porchctl rpkg push' detects a binary file in the kpt package
  • Loading branch information
nephio-prow[bot] authored Jul 22, 2024
2 parents 721c2e9 + 4dcaadc commit 170d423
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/cli/commands/rpkg/push/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path"
"path/filepath"
"strings"
"unicode/utf8"

porchapi "github.com/nephio-project/porch/api/porch/v1alpha1"
"github.com/nephio-project/porch/internal/kpt/errors"
Expand Down Expand Up @@ -241,6 +242,13 @@ func readFromDir(dir string) (map[string]string, error) {
if err != nil {
return err
}
if !utf8.Valid(contents) {
// Since PackageRevisionResources' spec.Resources is a map of strings, during JSON serialization all file contents
// will be converted to valid UTF-8 by changing invalid bytes to the Unicode replacement character.
// This of course corrupts the contents of binary files.
// Return an early error here to prevent pushing corrupt content.
return fmt.Errorf("file %s is not a valid UTF-8 text file: current porch API doesn't support binary files", path)
}
resources[rel] = string(contents)
return nil
}); err != nil {
Expand Down

0 comments on commit 170d423

Please sign in to comment.