2013-05-08 21:05:35 -07:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2018-01-22 17:21:10 -08:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-05-08 21:05:35 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdBuilder struct {
|
|
|
|
builder packer.Builder
|
2013-06-11 11:03:36 -07:00
|
|
|
client *Client
|
2013-05-08 21:05:35 -07:00
|
|
|
}
|
|
|
|
|
2013-11-02 22:51:26 -05:00
|
|
|
func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, error) {
|
2013-05-08 21:05:35 -07:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-14 12:27:50 -07:00
|
|
|
return b.builder.Prepare(config...)
|
2013-05-08 21:05:35 -07:00
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 12:11:58 +01:00
|
|
|
func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
2013-05-08 21:05:35 -07:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 12:11:58 +01:00
|
|
|
return b.builder.Run(ui, hook)
|
2013-05-08 21:05:35 -07:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:44:34 -07:00
|
|
|
func (b *cmdBuilder) Cancel() {
|
2013-06-03 15:31:28 -07:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
b.builder.Cancel()
|
2013-06-03 14:44:34 -07:00
|
|
|
}
|
|
|
|
|
2013-05-08 21:05:35 -07:00
|
|
|
func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
|
|
|
|
if c.client.Exited() && cb != nil {
|
|
|
|
cb()
|
2013-08-19 23:38:22 -07:00
|
|
|
} else if p != nil && !Killed {
|
2013-05-08 21:05:35 -07:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|