tempfile
tempfile copied to clipboard
Choose a writable temp dir please
Reading the docs for the windows temp dir selection, it goes through several fallbacks before it selects a dir:
https://docs.microsoft.com/en-gb/windows/win32/api/fileapi/nf-fileapi-gettemppatha
Would it be possible for this crate to check that the dir selected is writable by the current user before selecting it? ( See https://github.com/rust-lang/cargo/issues/4350 )
Ah that's a bit unfortunate! We could write our own alternative to env::temp_dir, like writable_temp_dir, that on Windows follows through the same environment variables, and on Linux just forwards to env::temp_dir.
Would you like to submit a PR that does something like this?
I'm not sure this is the right behavior. The docs imply that one should:
- Call
GetTempPathto get the location where temporary files should be written. - Check to make sure that this directory is accessible.
That's effectively what we're doing by trying to actually create a file/directory.
The docs don't say that one should check if the paths specified by TMP, TEMP, and USERPROFILE are writable in-turn.
From what I can tell, specifying a TMP that isn't writable is a misconfiguration. I'd rather fail early than work around it.
I would appreciate having a way to override the temporary directory that cargo uses somewhere in the configuration! I am on Linux, and /tmp is writeable. The build starts, but it runs out of memory whenever I a bigger crate is built!
/tmp is a tmpfs in the distribution I use, and limited to 8G!
IIRC the recommended place to use for bigger temporary data is /var/tmp on Linux, that would definitely held for my case.
I would love to be able to just set a tmpdir in the cargo configuration file! I do not want to globally set TMPDIR and I keep forgetting to do so whenever I run cargo.
@hunger please ask the cargo team for an override. That's not something this library can help with (and not related to this issue).
@Stebalien : Oh, sorry, I got here by following a link from the cargo bug tracker and had not noticed that I was in a different project now!
Writable isn't the only issue, if you can write files there but can't execute them, you are still going to get build failures. Not sure if that is a separate issue or just another unit/integration test to use against the code changes.