Skip to content

Commit

Permalink
Handle BigFilesTemproaryDir correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jun 16, 2021
1 parent f10e62c commit 92bd63e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libimage/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
}
Expand Down
7 changes: 6 additions & 1 deletion libimage/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions libimage/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 92bd63e

Please sign in to comment.