New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io/ioutil: TempDir fails if "/tmp" doesn't exist and first argument is empty #14196
Comments
Or we can just make the error message better. I don't like the idea of creating /tmp automatically, because my "/" filesystem is likely small, slow, read-only or otherwise special. I think it's a surprise to put /tmp there. If /tmp isn't there, it's probably because of some problem and I'd prefer to explode and learn about the problem than make things worse. Now that you know your problem, you can create /tmp in your Docker container and/or set TMPDIR. |
Yes, it's definitely something that can be addressed in the caller program. |
I've taken a stab at this with https://go-review.googlesource.com/19178. The only problem is, how could I test this as changing out os.TempDir is impractical. Also a code review is pending. |
ioutil gives a reference to the os.TempDir. Neither ioutil.TempDir or ioutil.TempFile are meant to be just working if an empty dir is given. I don't like the fact that we are returning a custom error from ioutil functions whereas users who depend on os.TempDir directly need to handle a different error. I think more docs would help, noting what happens if the directory doesn't exist. Your issue also applies for the arbitrary values of the dir. What does the following code suppose to return? Custom error?
|
I think of that case differently: since we explicitly selected a value, it's reasonable to expect the caller to set the environment up. |
CL https://golang.org/cl/19178 mentions this issue. |
CL https://golang.org/cl/28772 mentions this issue. |
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:
The text was updated successfully, but these errors were encountered: