9f82b75e57
* 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
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package safetemp
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Dir creates a new temporary directory that isn't yet created. This
|
|
// can be used with calls that expect a non-existent directory.
|
|
//
|
|
// The directory is created as a child of a temporary directory created
|
|
// within the directory dir starting with prefix. The temporary directory
|
|
// returned is always named "temp". The parent directory has the specified
|
|
// prefix.
|
|
//
|
|
// The returned io.Closer should be used to clean up the returned directory.
|
|
// This will properly remove the returned directory and any other temporary
|
|
// files created.
|
|
//
|
|
// If an error is returned, the Closer does not need to be called (and will
|
|
// be nil).
|
|
func Dir(dir, prefix string) (string, io.Closer, error) {
|
|
// Create the temporary directory
|
|
td, err := ioutil.TempDir(dir, prefix)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
return filepath.Join(td, "temp"), pathCloser(td), nil
|
|
}
|
|
|
|
// pathCloser implements io.Closer to remove the given path on Close.
|
|
type pathCloser string
|
|
|
|
// Close deletes this path.
|
|
func (p pathCloser) Close() error {
|
|
return os.RemoveAll(string(p))
|
|
}
|