summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorGuillaume Rose <gurose@redhat.com>2021-08-19 16:17:23 +0200
committerMatthew Heon <mheon@redhat.com>2021-08-20 11:37:16 -0400
commitb5e04ae115e0ed6a337d33a98ef70c8f45504040 (patch)
tree971ea2cf01c0af2d1aa97c9421dd88f895444d3c /pkg
parenta52b6bf23864073c39fda753b8c88a391bfe3555 (diff)
downloadpodman-b5e04ae115e0ed6a337d33a98ef70c8f45504040.tar.gz
podman-b5e04ae115e0ed6a337d33a98ef70c8f45504040.tar.bz2
podman-b5e04ae115e0ed6a337d33a98ef70c8f45504040.zip
machine: compute sha256 as we read the image file
It avoids to have the full file in memory. [NO TESTS NEEDED] Signed-off-by: Guillaume Rose <gurose@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/machine/fcos.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 943b9fd3c..49ec01e67 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -3,8 +3,6 @@
package machine
import (
- "crypto/sha256"
- "io/ioutil"
url2 "net/url"
"os"
"path/filepath"
@@ -12,6 +10,7 @@ import (
"strings"
digest "github.com/opencontainers/go-digest"
+ "github.com/sirupsen/logrus"
)
// These should eventually be moved into machine/qemu as
@@ -95,12 +94,19 @@ func UpdateAvailable(d *Download) (bool, error) {
if _, err := os.Stat(d.LocalPath); os.IsNotExist(err) {
return false, nil
}
- b, err := ioutil.ReadFile(d.LocalPath)
+ fd, err := os.Open(d.LocalPath)
+ if err != nil {
+ return false, err
+ }
+ defer func() {
+ if err := fd.Close(); err != nil {
+ logrus.Error(err)
+ }
+ }()
+ sum, err := digest.SHA256.FromReader(fd)
if err != nil {
return false, err
}
- s := sha256.Sum256(b)
- sum := digest.NewDigestFromBytes(digest.SHA256, s[:])
return sum.Encoded() == d.Sha256sum, nil
}