Conversation
0fcf3d5 to
9754d53
Compare
We used absolute paths in the builder when making directories and in `create_named` but this didn't cover `Builder::make_in` and technically introduced a small race in some unnamed tempfile cases (i.e., when we can't atomically create unnamed temporary files and need to create then immediately delete them). Instead, we now resolve the filename into an absolute path inside the main create helper.
9754d53 to
4517271
Compare
|
I want to report that this has caused breakage in my code that was written along the lines of Builder::new().make_in("", |filename| {
Ok(std::fs::File::from(rustix::fs::openat(dirfd, filename, flags, mode)?))
});functionally with the intent to use In the past the code would properly create the temporary file within directory referenced by To be fair there is nothing in the documentation of |
|
Hm. The issue is that tempfile needs to know where exactly the file lives so it can correctly delete it. In your case, it would have attempted to delete I'm curious, what's your use-case? I've considered supporting directory-relative temporary files (#40) but I've never had a strong use-case. |
|
Aha, nicely spotted. Yeah, deletion would have probably been buggy too. The only reason I hadn't hit it was because in the happy path all of these temporary files would get retained ( To elaborate more on the overarching use-case: my code is implementing a filesystem-level cache. One of the concerns are that the lookups for a given filename should only succeed once the value has been fully written (hence the To be honest I don't mind at all implementing all of that funky logic myself, |
We used absolute paths in the builder when making directories and in `create_named` but this didn't cover `Builder::make_in` and technically introduced a small race in some unnamed tempfile cases (i.e., when we can't atomically create unnamed temporary files and need to create then immediately delete them). Instead, we now resolve the filename into an absolute path inside the main create helper.
We used absolute paths in the builder when making directories and in
create_namedbut this didn't coverBuilder::make_inand technically introduced a small race in some unnamed tempfile cases (i.e., when we can't atomically create unnamed temporary files and need to create then immediately delete them).Instead, we now resolve the filename into an absolute path inside the main create helper.