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

machine: compute sha256 as we are reading the file #11279

Merged
merged 2 commits into from
Aug 19, 2021
Merged
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
29 changes: 14 additions & 15 deletions pkg/machine/fcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
package machine

import (
"crypto/sha256"
"io/ioutil"
url2 "net/url"
"os"
"path/filepath"
"runtime"
"strings"

digest "github.com/opencontainers/go-digest"
"github.com/sirupsen/logrus"
)

// These should eventually be moved into machine/qemu as
Expand Down Expand Up @@ -91,24 +91,23 @@ func UpdateAvailable(d *Download) (bool, error) {
// check the sha of the local image if it exists
// get the sha of the remote image
// == dont bother to pull
files, err := ioutil.ReadDir(filepath.Dir(d.LocalPath))
if _, err := os.Stat(d.LocalPath); os.IsNotExist(err) {
return false, nil
}
fd, err := os.Open(d.LocalPath)
if err != nil {
return false, err
}
for _, file := range files {
if filepath.Base(d.LocalPath) == file.Name() {
b, err := ioutil.ReadFile(d.LocalPath)
if err != nil {
return false, err
}
s := sha256.Sum256(b)
sum := digest.NewDigestFromBytes(digest.SHA256, s[:])
if sum.Encoded() == d.Sha256sum {
return true, nil
}
defer func() {
if err := fd.Close(); err != nil {
logrus.Error(err)
}
}()
sum, err := digest.SHA256.FromReader(fd)
if err != nil {
return false, err
}
return false, nil
return sum.Encoded() == d.Sha256sum, nil
}

func getFcosArch() string {
Expand Down