build: ensure temporary folder is removed in error case
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
6c60bb4436
commit
00792d1704
@ -100,11 +100,16 @@ func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool,
|
|||||||
// WriteTempDockerfile writes a Dockerfile stream to a temporary file with a
|
// WriteTempDockerfile writes a Dockerfile stream to a temporary file with a
|
||||||
// name specified by DefaultDockerfileName and returns the path to the
|
// name specified by DefaultDockerfileName and returns the path to the
|
||||||
// temporary directory containing the Dockerfile.
|
// temporary directory containing the Dockerfile.
|
||||||
func WriteTempDockerfile(rc io.ReadCloser) (string, error) {
|
func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) {
|
||||||
dockerfileDir, err := ioutil.TempDir("", "docker-build-tempdockerfile-")
|
dockerfileDir, err = ioutil.TempDir("", "docker-build-tempdockerfile-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Errorf("unable to create temporary context directory: %v", err)
|
return "", errors.Errorf("unable to create temporary context directory: %v", err)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
os.RemoveAll(dockerfileDir)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
f, err := os.Create(filepath.Join(dockerfileDir, DefaultDockerfileName))
|
f, err := os.Create(filepath.Join(dockerfileDir, DefaultDockerfileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user