Skip to content

Commit 08b43d9

Browse files
Merge pull request #2325 from cloudfoundry-incubator/pr-tempdir
Use user-specific temp directory if set
2 parents 40c3acd + fc8bce5 commit 08b43d9

6 files changed

Lines changed: 14 additions & 7 deletions

File tree

archive/tar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func applyNaive(ctx context.Context, root string, tr *tar.Reader, options ApplyO
199199
basename := filepath.Base(hdr.Name)
200200
aufsHardlinks[basename] = hdr
201201
if aufsTempdir == "" {
202-
if aufsTempdir, err = ioutil.TempDir("", "dockerplnk"); err != nil {
202+
if aufsTempdir, err = ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "dockerplnk"); err != nil {
203203
return 0, err
204204
}
205205
defer os.RemoveAll(aufsTempdir)

cmd/ctr/commands/content/content.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ var (
506506
)
507507

508508
func edit(rd io.Reader) (io.ReadCloser, error) {
509-
tmp, err := ioutil.TempFile("", "edit-")
509+
tmp, err := ioutil.TempFile(os.Getenv("XDG_RUNTIME_DIR"), "edit-")
510510
if err != nil {
511511
return nil, err
512512
}

contrib/apparmor/apparmor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func WithDefaultProfile(name string) oci.SpecOpts {
5353
if err != nil {
5454
return err
5555
}
56-
f, err := ioutil.TempFile("", p.Name)
56+
f, err := ioutil.TempFile(os.Getenv("XDG_RUNTIME_DIR"), p.Name)
5757
if err != nil {
5858
return err
5959
}

mount/temp.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/pkg/errors"
2626
)
2727

28-
var tempMountLocation = os.TempDir()
28+
var tempMountLocation = getTempDir()
2929

3030
// WithTempMount mounts the provided mounts to a temp dir, and pass the temp dir to f.
3131
// The mounts are valid during the call to the f.
@@ -64,3 +64,10 @@ func WithTempMount(ctx context.Context, mounts []Mount, f func(root string) erro
6464
}
6565
return errors.Wrapf(f(root), "mount callback failed on %s", root)
6666
}
67+
68+
func getTempDir() string {
69+
if xdg := os.Getenv("XDG_RUNTIME_DIR"); xdg != "" {
70+
return xdg
71+
}
72+
return os.TempDir()
73+
}

rootfs/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func createInitLayer(ctx context.Context, parent, initName string, initFn func(s
7575
// TODO: ensure not exist error once added to snapshot package
7676

7777
// Create tempdir
78-
td, err := ioutil.TempDir("", "create-init-")
78+
td, err := ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "create-init-")
7979
if err != nil {
8080
return "", err
8181
}

services/tasks/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
114114
err error
115115
)
116116
if r.Checkpoint != nil {
117-
checkpointPath, err = ioutil.TempDir("", "ctrd-checkpoint")
117+
checkpointPath, err = ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "ctrd-checkpoint")
118118
if err != nil {
119119
return nil, err
120120
}
@@ -450,7 +450,7 @@ func (l *local) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest, _
450450
if err != nil {
451451
return nil, err
452452
}
453-
image, err := ioutil.TempDir("", "ctd-checkpoint")
453+
image, err := ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "ctd-checkpoint")
454454
if err != nil {
455455
return nil, errdefs.ToGRPC(err)
456456
}

0 commit comments

Comments
 (0)