2013-05-09 00:05:35 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-05-09 00:05:35 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type cmdBuilder struct {
|
|
|
|
builder packer.Builder
|
2013-06-11 14:03:36 -04:00
|
|
|
client *Client
|
2013-05-09 00:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-11-02 23:51:26 -04:00
|
|
|
func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, error) {
|
2013-05-09 00:05:35 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-14 15:27:50 -04:00
|
|
|
return b.builder.Prepare(config...)
|
2013-05-09 00:05:35 -04: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 07:11:58 -04:00
|
|
|
func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
2013-05-09 00:05:35 -04: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 07:11:58 -04:00
|
|
|
return b.builder.Run(ui, hook)
|
2013-05-09 00:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-06-03 17:44:34 -04:00
|
|
|
func (b *cmdBuilder) Cancel() {
|
2013-06-03 18:31:28 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
b.builder.Cancel()
|
2013-06-03 17:44:34 -04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:05:35 -04:00
|
|
|
func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
|
|
|
|
if c.client.Exited() && cb != nil {
|
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-05-09 00:05:35 -04:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|