@@ -6,6 +6,7 @@ package getter
66import (
77 "bufio"
88 "bytes"
9+ "context"
910 "crypto/md5"
1011 "crypto/sha1"
1112 "crypto/sha256"
@@ -80,23 +81,27 @@ func (c *FileChecksum) checksum(source string) error {
8081// extractChecksum will return a FileChecksum based on the 'checksum'
8182// parameter of u.
8283// ex:
83- // http://hashicorp.com/terraform?checksum=<checksumValue>
84- // http://hashicorp.com/terraform?checksum=<checksumType>:<checksumValue>
85- // http://hashicorp.com/terraform?checksum=file:<checksum_url>
84+ //
85+ // http://hashicorp.com/terraform?checksum=<checksumValue>
86+ // http://hashicorp.com/terraform?checksum=<checksumType>:<checksumValue>
87+ // http://hashicorp.com/terraform?checksum=file:<checksum_url>
88+ //
8689// when checksumming from a file, extractChecksum will go get checksum_url
8790// in a temporary directory, parse the content of the file then delete it.
8891// Content of files are expected to be BSD style or GNU style.
8992//
9093// BSD-style checksum:
91- // MD5 (file1) = <checksum>
92- // MD5 (file2) = <checksum>
94+ //
95+ // MD5 (file1) = <checksum>
96+ // MD5 (file2) = <checksum>
9397//
9498// GNU-style:
95- // <checksum> file1
96- // <checksum> *file2
99+ //
100+ // <checksum> file1
101+ // <checksum> *file2
97102//
98103// see parseChecksumLine for more detail on checksum file parsing
99- func (c * Client ) extractChecksum (u * url.URL ) (* FileChecksum , error ) {
104+ func (c * Client ) extractChecksum (ctx context. Context , u * url.URL ) (* FileChecksum , error ) {
100105 q := u .Query ()
101106 v := q .Get ("checksum" )
102107
@@ -118,7 +123,7 @@ func (c *Client) extractChecksum(u *url.URL) (*FileChecksum, error) {
118123
119124 switch checksumType {
120125 case "file" :
121- return c .ChecksumFromFile (checksumValue , u )
126+ return c .ChecksumFromFile (ctx , checksumValue , u )
122127 default :
123128 return newChecksumFromType (checksumType , checksumValue , filepath .Base (u .EscapedPath ()))
124129 }
@@ -193,7 +198,7 @@ func newChecksumFromValue(checksumValue, filename string) (*FileChecksum, error)
193198//
194199// ChecksumFromFile will only return checksums for files that match file
195200// behind src
196- func (c * Client ) ChecksumFromFile (checksumFile string , src * url.URL ) (* FileChecksum , error ) {
201+ func (c * Client ) ChecksumFromFile (ctx context. Context , checksumFile string , src * url.URL ) (* FileChecksum , error ) {
197202 checksumFileURL , err := urlhelper .Parse (checksumFile )
198203 if err != nil {
199204 return nil , err
@@ -206,7 +211,6 @@ func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileCheck
206211 defer os .Remove (tempfile )
207212
208213 c2 := & Client {
209- Ctx : c .Ctx ,
210214 Getters : c .Getters ,
211215 Decompressors : c .Decompressors ,
212216 Detectors : c .Detectors ,
@@ -216,7 +220,7 @@ func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileCheck
216220 Dst : tempfile ,
217221 ProgressListener : c .ProgressListener ,
218222 }
219- if err = c2 .Get (); err != nil {
223+ if err = c2 .Get (ctx ); err != nil {
220224 return nil , fmt .Errorf (
221225 "Error downloading checksum file: %s" , err )
222226 }
0 commit comments