Closed Stebalien closed 3 months ago
(needs test)
Generally I am not sure if it makes sense to limit the override function to be only called once. Is there a technical reason why you want to prevent it? It was possible before to call set_env
multiple times.
For example, a system utility running during boot (initrd) might need to change its temporary directory after mounting some file systems.
I can relax the constraints later if someone presents a strong use-case, but tightening them isn't possible so I'm starting with the strongest constraints.
My reason is that override_temp_dir
exists only to handle the case where the OS doesn't set an appropriate temporary directory. It's a last-resort escape hatch. I don't want is multiple libraries calling override_temp_dir
, then getting confused when their setting gets clobbered by some other library.
In general, applications needing to put specific files in specific directories should use tempfile_in
and friends.
For example, a system utility running during boot (initrd) might need to change its temporary directory after mounting some file systems.
Init systems re-exec themselves for this reason. Changing the tempdir at runtime likely isn't going to have the desired result (old temporary files will still live in the old location).
Merging this for now. I'll release at the end of the week so we can continue our discussion until then (and possibly iterate on the design).
This adds a new
env
module withoverride_temp_dir
andtemp_dir
functions.temp_dir
will defer tostd::env::temp_dir
by default unless the temporary directory has been overridden.override_temp_dir
allows the user to override the default temporary directory ONCE. Once this value has been set, it cannot be changed Care should be taken to ensure that the chosen directory is actually writable.This API is designed for use by the application author when the application may run in an environment without a reliable global temporary directory (e.g., Android).
fixes #285