Ubuntu Pastebin

Paste from egon at Thu, 23 Nov 2017 09:38:29 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
diff --git a/image/helpers.go b/image/helpers.go
index 828887ee8..d3e6319c0 100644
--- a/image/helpers.go
+++ b/image/helpers.go
@@ -22,6 +22,7 @@ package image
 // TODO: put these in appropriate package(s) once they are clarified a bit more
 
 import (
+	"crypto"
 	"encoding/json"
 	"fmt"
 	"os"
@@ -31,6 +32,7 @@ import (
 
 	"github.com/snapcore/snapd/asserts"
 	"github.com/snapcore/snapd/asserts/snapasserts"
+	"github.com/snapcore/snapd/osutil"
 	"github.com/snapcore/snapd/overlord/auth"
 	"github.com/snapcore/snapd/progress"
 	"github.com/snapcore/snapd/release"
@@ -144,6 +146,14 @@ func (tsto *ToolingStore) DownloadSnap(name string, revision snap.Revision, opts
 	baseName := filepath.Base(snap.MountFile())
 	targetFn = filepath.Join(targetDir, baseName)
 
+	// check if we already have the right file
+	if osutil.FileExists(targetFn) {
+		sha3_384Dgst, size, err := osutil.FileDigest(targetFn, crypto.SHA3_384)
+		if err == nil && size == uint64(snap.DownloadInfo.Size) && fmt.Sprintf("%x", sha3_384Dgst) == snap.DownloadInfo.Sha3_384 {
+			return targetFn, snap, nil
+		}
+	}
+
 	pb := progress.MakeProgressBar()
 	defer pb.Finished()
 
Download as text