Skip to content

io/ioutil: TempDir fails if "/tmp" doesn't exist and first argument is empty #14196

@deweerdt

Description

@deweerdt

Seen on go1.5.2 linux/amd64, running a program using io.ioutil.TempDir() inside a docker image that has neither TMPDIR defined nor /tmp created.
Calling io.ioutil.TempDir() fails with: mkdir ... no such file or directory.

In the special case where TempDir (or TempFile) are called with an empty first argument, it feels like we could try to mkdir the directory before erroring out of the function.

Small repro case:

$ cat test1.go
package main

import (
        "io/ioutil"
)

func main() {
        _, err := ioutil.TempDir("", "blah")
        if err != nil {
                println(err.Error())
        }
}
$ go build test1.go
$ mkdir dir
$ mv test1 dir
$ sudo chroot ./dir /test1
mkdir /tmp/blah629598329: no such file or directory
$

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions