Skip to content
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

Closed
ibukanov opened this issue Jan 19, 2016 · 5 comments
Closed

os: TempDir and /var/tmp #14021

ibukanov opened this issue Jan 19, 2016 · 5 comments
Milestone

Comments

@ibukanov
Copy link

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.

@ianlancetaylor ianlancetaylor changed the title os.TempDir() and /var/tmp os: TempDir and /var/tmp Jan 19, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Jan 19, 2016
@ianlancetaylor
Copy link
Contributor

I'm not sure whether we want a new function or not, but marking this as Go1.7 to decide.

@rakyll
Copy link
Contributor

rakyll commented Jan 19, 2016

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.

@minux
Copy link
Member

minux commented Jan 19, 2016 via email

@ibukanov
Copy link
Author

@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?

@dominikh
Copy link
Member

that /tmp was perfectly OK for big files

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.

Still, what about changing the default for TempDir to return /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.

@golang golang locked and limited conversation to collaborators Jan 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants