Closed mamcx closed 1 year ago
You need to specify a prefix for the tempdir name? Or do you just need to specify a location. If you need to specify a location, TempDir::new_in(...)
should do it.
TempDir::new_in(...)
does not work because that needs that folder created, the old tempdir crate make it.
Hm. I don't think I'm on the same page. Could you explain exactly what you're trying to do and the desired effect?
The desired effect is to recover the behaviour of the old Tempdir::new
, I think the equivalent now is tempfile::Builder::new().prefix(prefix).tempdir()
?
It add + create a folder with the prefix...
I'll consider it, but a stronger motivation beyond "I want to do this" would be helpful. Personally, I usually care about where my temporary files go, but rarely care about their names.
Understood. We have a battery of test that run on parallel and we use the same temp_folder
but distinct names for each, so the idea is that we have:
/tmp/test_a
/tmp/test_b
/tmp/test_c
without causing interferences, and having names help in debugging issues, that is very hard to do if the names are machine generated!
Also if used outside the test, this show up in logs and is nicer to see that this particular temp file was part of certain "context".
Yeah, that makes sense. My concern is that I could add TempDir::with_prefix(prefix)
, but then what about TempDir::with_prefix_in(prefix, directory)
? In retrospect, new
on both TempDir
and NamedTempFile
should have always taken a prefix (costs the user nothing to specify one) but that ship has sailed.
Yeah, ok, I should probably just do it. Now to the question of names:
with_prefix
(with_prefix_in
)prefixed
(prefixed_in
)new_with_prefix
(new_with_prefix_in
)new_prefixed
(new_prefixed_in
).I'm thinking the first one.
Yes with_
sounds good.
I want to remove the dependabot for https://github.com/advisories/GHSA-mc8h-8q98-g5hr and I miss the old
TempDir:new('foo')
call.The available constructors have different semantics and the proposed solution is kinda verbose:
tempfile::Builder::new().prefix(prefix).tempdir()