summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Rose <gurose@redhat.com>2021-08-19 16:14:06 +0200
committerGuillaume Rose <gurose@redhat.com>2021-08-19 16:54:44 +0200
commit0434571920939576b1708e905cfb156d9fde504b (patch)
treea2b843f53fd60f1b11c94e6112a3889a8ed0f51f
parent23804d95f6589eca37e7cdcfcfaeb1e63e47b209 (diff)
downloadpodman-0434571920939576b1708e905cfb156d9fde504b.tar.gz
podman-0434571920939576b1708e905cfb156d9fde504b.tar.bz2
podman-0434571920939576b1708e905cfb156d9fde504b.zip
machine: check for file exists instead of listing directory
[NO TESTS NEEDED] Signed-off-by: Guillaume Rose <gurose@redhat.com>
-rw-r--r--pkg/machine/fcos.go23
1 files changed, 8 insertions, 15 deletions
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 11936aee7..943b9fd3c 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -6,6 +6,7 @@ import (
"crypto/sha256"
"io/ioutil"
url2 "net/url"
+ "os"
"path/filepath"
"runtime"
"strings"
@@ -91,24 +92,16 @@ 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
+ }
+ b, err := ioutil.ReadFile(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
- }
- }
- }
- return false, nil
+ s := sha256.Sum256(b)
+ sum := digest.NewDigestFromBytes(digest.SHA256, s[:])
+ return sum.Encoded() == d.Sha256sum, nil
}
func getFcosArch() string {