-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: TempDir and /var/tmp #14021
Comments
I'm not sure whether we want a new function or not, but marking this as Go1.7 to decide. |
I don't think /var/tmp would stand for a "permanent" temp directory. The reason why os.TempDir exists is the fragmentation among operating systems where temp files must be written and TempDir is doing fair job and is useful for programs that will be distributed among multiple platforms. What is the equivalent of persistent temp directory on other platforms? If you are only targeting Linux, why don't you just hardcode /var/tmp? In any case, TEMPDIR is honored by io.TempDir and ioutil.Tmp* utilities can create directories and files against its value. |
I don't think we should blame Go's API for the problem with docker
creating temp. images in tmpfs backed /tmp.
A user facing application should detect free space available if it's
going to create huge temporary files in anywhere, even it's in /var/tmp.
(I'd like if we could add an API to query available free space to the os
package though.)
Go's temp file/dir API respect $TMPDIR, so think it's enough. And
in fact, I've seen systems with $TMPDIR set to /var/tmp and only
applications with hardcoded tmp directory use /tmp.
|
@minux You are right that one cannot blame Go. In fact after some thinking I think the blame should go to RedHat or whoever first broke the long tradition that /tmp was perfectly OK for big files breaking the existing code. Still, what about changing the default for TempDir to return /var/tmp? |
I can't agree that that was ever the case. And considering the size of my /var partition, you would be more happy with my memory-backed /tmp than my disk-backed /var/tmp.
I would consider this a breaking change. /tmp and /var/tmp are entirely different things. And people certainly wouldn't want large files sticking around because a program failed to clean up behind itself (system crash or similar). Maybe Docker shouldn't abuse either /tmp nor /var/tmp and look into defining its own path under /var/cache or similar. |
On modern Linux /tmp is often mounted as in-memory file system not suitable for large temporary files. Such files or files that should survive a reboot should be stored in /var/tmp. Yet Go does not provide a convenient method to access the latter and most code just use os.TempDir() for temporary files. This leads to bugs like when Docker used /tmp for big temporary image files leading to not-enough-space errors.
So it would be nice to have something like os.PersistentTempDir() that returns /var/tmp on Linux.
The text was updated successfully, but these errors were encountered: