Skip to content

Commit

Permalink
Allow users to set TMPDIR environment
Browse files Browse the repository at this point in the history
Some users have small /var/tmp directories and need to be able to specify a different location
for temporary files, which includes more space.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Mar 6, 2020
1 parent f07e18f commit cb51707
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/podman/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/shared/parse"
"github.com/containers/libpod/pkg/adapter"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
Expand Down Expand Up @@ -75,7 +76,7 @@ func loadCmd(c *cliconfig.LoadValues) error {
if terminal.IsTerminal(int(os.Stdin.Fd())) {
return errors.Errorf("cannot read from terminal. Use command-line redirection or the --input flag.")
}
outFile, err := ioutil.TempFile("/var/tmp", "podman")
outFile, err := ioutil.TempFile(util.Tmpdir(), "podman")
if err != nil {
return errors.Errorf("error creating file %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,8 @@ b
**/etc/subuid**
**/etc/subgid**

NOTE: Use the environment variable `TMPDIR` to change the temporary storage location of downloaded container images. Podman defaults to use `/var/tmp`.

## SEE ALSO
subgid(5), subuid(5), libpod.conf(5), systemd.unit(5), setsebool(8), slirp4netns(1), fuse-overlayfs(1)

Expand Down
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-load.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Read from archive file, default is STDIN.

The remote client requires the use of this option.

NOTE: Use the environment variable `TMPDIR` to change the temporary storage location of container images. Podman defaults to use `/var/tmp`.

**--quiet**, **-q**

Suppress the progress output
Expand Down
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-pull.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ Storing signatures

registries.conf is the configuration file which specifies which container registries should be consulted when completing image names which do not include a registry or domain portion.

NOTE: Use the environment variable `TMPDIR` to change the temporary storage location of downloaded container images. Podman defaults to use `/var/tmp`.

## SEE ALSO
podman(1), podman-push(1), podman-login(1), containers-registries.conf(5)

Expand Down
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,8 @@ b

**/etc/subgid**

NOTE: Use the environment variable `TMPDIR` to change the temporary storage location of downloaded container images. Podman defaults to use `/var/tmp`.

## SEE ALSO
**subgid**(5), **subuid**(5), **libpod.conf**(5), **systemd.unit**(5), **setsebool**(8), **slirp4netns**(1), **fuse-overlayfs**(1).

Expand Down
8 changes: 4 additions & 4 deletions libpod/runtime_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ func (r *Runtime) Import(ctx context.Context, source string, reference string, c
}

// donwloadFromURL downloads an image in the format "https:/example.com/myimage.tar"
// and temporarily saves in it /var/tmp/importxyz, which is deleted after the image is imported
// and temporarily saves in it $TMPDIR/importxyz, which is deleted after the image is imported
func downloadFromURL(source string) (string, error) {
fmt.Printf("Downloading from %q\n", source)

outFile, err := ioutil.TempFile("/var/tmp", "import")
outFile, err := ioutil.TempFile(util.Tmpdir(), "import")
if err != nil {
return "", errors.Wrap(err, "error creating file")
}
Expand All @@ -234,9 +234,9 @@ func downloadFromURL(source string) (string, error) {
}

// DownloadFromFile reads all of the content from the reader and temporarily
// saves in it /var/tmp/importxyz, which is deleted after the image is imported
// saves in it $TMPDIR/importxyz, which is deleted after the image is imported
func DownloadFromFile(reader *os.File) (string, error) {
outFile, err := ioutil.TempFile("/var/tmp", "import")
outFile, err := ioutil.TempFile(util.Tmpdir(), "import")
if err != nil {
return "", errors.Wrap(err, "error creating file")
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,12 @@ func HomeDir() (string, error) {
}
return home, nil
}

func Tmpdir() string {
tmpdir := os.Getenv("TMPDIR")
if tmpdir == "" {
tmpdir = "/var/tmp"
}

return tmpdir
}

0 comments on commit cb51707

Please sign in to comment.