tempfile icon indicating copy to clipboard operation
tempfile copied to clipboard

Choose a writable temp dir please

Open gilescope opened this issue 6 years ago • 5 comments

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 )

gilescope avatar Nov 09 '19 06:11 gilescope

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?

KodrAus avatar Nov 09 '19 10:11 KodrAus

I'm not sure this is the right behavior. The docs imply that one should:

  1. Call GetTempPath to get the location where temporary files should be written.
  2. 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.

Stebalien avatar Nov 09 '19 20:11 Stebalien

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 avatar Nov 26 '20 17:11 hunger

@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 avatar Nov 30 '20 19:11 Stebalien

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

hunger avatar Dec 02 '20 16:12 hunger

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.

spoelstraethan avatar Oct 16 '23 22:10 spoelstraethan