Skip to content

Commit

Permalink
Merge pull request #8694 from johngmyers/fix-fileassets
Browse files Browse the repository at this point in the history
Fix uploading of file assets
  • Loading branch information
k8s-ci-robot committed Mar 10, 2020
2 parents 92ca7bf + fc7a955 commit 5c01bff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
10 changes: 5 additions & 5 deletions upup/pkg/fi/assettasks/copyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ func transferFile(c *fi.Context, source string, target string, sha string) error
return fmt.Errorf("error building path %q: %v", shaTarget, err)
}

in := bytes.NewReader(data)
dataHash, err := hashing.HashAlgorithmSHA1.Hash(in)
shaHash, err := hashing.FromString(strings.TrimSpace(sha))
if err != nil {
return fmt.Errorf("unable to parse sha from file %q downloaded: %v", sha, err)
return fmt.Errorf("unable to parse sha: %q, %v", sha, err)
}

shaHash, err := hashing.FromString(strings.TrimSpace(sha))
in := bytes.NewReader(data)
dataHash, err := shaHash.Algorithm.Hash(in)
if err != nil {
return fmt.Errorf("unable to hash sha: %q, %v", sha, err)
return fmt.Errorf("unable to hash file %q downloaded: %v", source, err)
}

if !shaHash.Equal(dataHash) {
Expand Down
24 changes: 0 additions & 24 deletions util/pkg/hashing/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,6 @@ func (ha HashAlgorithm) HashFile(p string) (*Hash, error) {
return ha.Hash(f)
}

func HashesForResource(r io.Reader, hashAlgorithms []HashAlgorithm) ([]*Hash, error) {
var hashers []hash.Hash
var writers []io.Writer
for _, hashAlgorithm := range hashAlgorithms {
hasher := hashAlgorithm.NewHasher()
hashers = append(hashers, hasher)
writers = append(writers, hasher)
}

w := io.MultiWriter(writers...)

_, err := copyToHasher(w, r)
if err != nil {
return nil, fmt.Errorf("error while hashing resource: %v", err)
}

var hashes []*Hash
for i, hasher := range hashers {
hashes = append(hashes, &Hash{Algorithm: hashAlgorithms[i], HashValue: hasher.Sum(nil)})
}

return hashes, nil
}

func copyToHasher(dest io.Writer, src io.Reader) (int64, error) {
n, err := io.Copy(dest, src)
if err != nil {
Expand Down

0 comments on commit 5c01bff

Please sign in to comment.