From 92bd63e9b7ee1d4a6a3252f4ff81029351323ccb Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 16 Jun 2021 08:49:27 -0400 Subject: [PATCH] Handle BigFilesTemproaryDir correctly Signed-off-by: Daniel J Walsh --- libimage/download.go | 4 ++-- libimage/runtime.go | 7 ++++++- libimage/runtime_test.go | 1 + 3 files changed, 9 insertions(+), 3 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..592f1d7a2 100644 --- a/libimage/runtime.go +++ b/libimage/runtime.go @@ -81,8 +81,13 @@ func RuntimeFromStore(store storage.Store, options *RuntimeOptions) (*Runtime, e var systemContext types.SystemContext if options.SystemContext != nil { systemContext = *options.SystemContext + if systemContext.BigFilesTemporaryDir == "" { + systemContext.BigFilesTemporaryDir = tmpdir() + } } else { - systemContext = types.SystemContext{} + systemContext = types.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)