diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-08-19 14:50:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-19 14:50:26 -0400 |
commit | f988cfe1463f795f51f64e0887ba9dd9fe85b23d (patch) | |
tree | ec325074c22051001eee3f76bb8fc0cfc64577be /pkg | |
parent | a3f4fbd176e55040aa43ad461616e4d47cedc600 (diff) | |
parent | b19812b5a245eec1f04da77f15d86004bd42d3fd (diff) | |
download | podman-f988cfe1463f795f51f64e0887ba9dd9fe85b23d.tar.gz podman-f988cfe1463f795f51f64e0887ba9dd9fe85b23d.tar.bz2 podman-f988cfe1463f795f51f64e0887ba9dd9fe85b23d.zip |
Merge pull request #11279 from guillaumerose/refactor1
machine: compute sha256 as we are reading the file
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/machine/fcos.go | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go index 11936aee7..49ec01e67 100644 --- a/pkg/machine/fcos.go +++ b/pkg/machine/fcos.go @@ -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 @@ -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 { |