mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
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>
This commit is contained in:
@ -3,8 +3,6 @@
|
|||||||
package machine
|
package machine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
|
||||||
"io/ioutil"
|
|
||||||
url2 "net/url"
|
url2 "net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -12,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These should eventually be moved into machine/qemu as
|
// 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) {
|
if _, err := os.Stat(d.LocalPath); os.IsNotExist(err) {
|
||||||
return false, nil
|
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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
s := sha256.Sum256(b)
|
|
||||||
sum := digest.NewDigestFromBytes(digest.SHA256, s[:])
|
|
||||||
return sum.Encoded() == d.Sha256sum, nil
|
return sum.Encoded() == d.Sha256sum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user