Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
e65e2d10
Commit
e65e2d10
authored
Jun 08, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: StepDownload can force an extension
parent
0885e03b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
common/step_download.go
common/step_download.go
+19
-2
No files found.
common/step_download.go
View file @
e65e2d10
package
common
package
common
import
(
import
(
"crypto/sha1"
"encoding/hex"
"encoding/hex"
"fmt"
"fmt"
"log"
"log"
...
@@ -36,6 +37,12 @@ type StepDownload struct {
...
@@ -36,6 +37,12 @@ type StepDownload struct {
// A list of URLs to attempt to download this thing.
// A list of URLs to attempt to download this thing.
Url
[]
string
Url
[]
string
// Extension is the extension to force for the file that is downloaded.
// Some systems require a certain extension. If this isn't set, the
// extension on the URL is used. Otherwise, this will be forced
// on the downloaded file for every URL.
Extension
string
}
}
func
(
s
*
StepDownload
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
StepDownload
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
...
@@ -60,9 +67,19 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -60,9 +67,19 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction {
targetPath
:=
s
.
TargetPath
targetPath
:=
s
.
TargetPath
if
targetPath
==
""
{
if
targetPath
==
""
{
// Determine a cache key. This is normally just the URL but
// if we force a certain extension we hash the URL and add
// the extension to force it.
cacheKey
:=
url
if
s
.
Extension
!=
""
{
hash
:=
sha1
.
Sum
([]
byte
(
url
))
cacheKey
=
fmt
.
Sprintf
(
"%s.%s"
,
hex
.
EncodeToString
(
hash
[
:
]),
s
.
Extension
)
}
log
.
Printf
(
"Acquiring lock to download: %s"
,
url
)
log
.
Printf
(
"Acquiring lock to download: %s"
,
url
)
targetPath
=
cache
.
Lock
(
url
)
targetPath
=
cache
.
Lock
(
cacheKey
)
defer
cache
.
Unlock
(
url
)
defer
cache
.
Unlock
(
cacheKey
)
}
}
config
:=
&
DownloadConfig
{
config
:=
&
DownloadConfig
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment