Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #8694: Fix uploading of file assets #8720

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions upup/pkg/fi/assettasks/copyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,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