From 55cace92833192234a00e298b33dcaabe532ebf0 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 16 Jun 2021 08:49:27 -0400 Subject: [PATCH] Handle BigFilesTemporaryDir correctly Signed-off-by: Daniel J Walsh --- libimage/download.go | 4 ++-- libimage/runtime.go | 3 +++ libimage/runtime_test.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libimage/download.go b/libimage/download.go index 5ea11f084..54edf1b9a 100644 --- a/libimage/download.go +++ b/libimage/download.go @@ -11,7 +11,7 @@ import ( ) // tmpdir returns a path to a temporary directory. -func (r *Runtime) tmpdir() string { +func tmpdir() string { tmpdir := os.Getenv("TMPDIR") if tmpdir == "" { tmpdir = "/var/tmp" @@ -25,7 +25,7 @@ func (r *Runtime) tmpdir() string { func (r *Runtime) downloadFromURL(source string) (string, error) { fmt.Printf("Downloading from %q\n", source) - outFile, err := ioutil.TempFile(r.tmpdir(), "import") + outFile, err := ioutil.TempFile(r.systemContext.BigFilesTemporaryDir, "import") if err != nil { return "", errors.Wrap(err, "error creating file") } diff --git a/libimage/runtime.go b/libimage/runtime.go index 93a42eb55..efa182544 100644 --- a/libimage/runtime.go +++ b/libimage/runtime.go @@ -84,6 +84,9 @@ func RuntimeFromStore(store storage.Store, options *RuntimeOptions) (*Runtime, e } else { systemContext = types.SystemContext{} } + if systemContext.BigFilesTemporaryDir == "" { + systemContext.BigFilesTemporaryDir = tmpdir() + } setRegistriesConfPath(&systemContext) diff --git a/libimage/runtime_test.go b/libimage/runtime_test.go index c23aedb13..c33c4721f 100644 --- a/libimage/runtime_test.go +++ b/libimage/runtime_test.go @@ -38,6 +38,7 @@ func testNewRuntime(t *testing.T) (runtime *Runtime, cleanup func()) { runtime, err = RuntimeFromStoreOptions(&RuntimeOptions{SystemContext: systemContext}, storeOptions) require.NoError(t, err) + require.Equal(t, runtime.systemContext.BigFilesTemporaryDir, tmpdir()) cleanup = func() { runtime.Shutdown(true)