Tempfile V4
This is a stack of changes for tempfile v4. My plan is to wait for the next Debian stable release then set the MSRV to that, although I may merge and cut an RC before then. This version tries to be minimally breaking in "normal" code but it will still break some code (ideally code that was already broken/buggy).
Other than the MSRV bump (letting us drop once_cell), changes include:
- Implement
AsRef<Path>on&NamedTempFile(and friends) instead of directly onNamedTempFile. That way, functions acceptingAsRef<Path>won't be able to take (then drop)NamedTempFileby value. See https://github.com/Stebalien/tempfile/issues/115. - Temporary directories are created with 0700 permissions by default instead of 0755 to match temporary files.
- Temporary filenames no longer start with a
.by default. Temporary files shouldn't generally be hidden. Additionally, it's now possible to configure the default temporary-filename prefix via theenvpackage. - The
Buildercan now has a single lifetime instead of separate ones forprefixandsuffix. It can also be constructed with a constBuilder::newif desired. - Temporary file names are validated to be valid file-names, not including path separators, etc. It's still not safe to allow an attacker to control the prefix/suffix, but this gives us a little extra safety.
- The closure passed to
Builder::makeused to take a&Pathbut now takes an&MakeParamsstruct (that dereferences to a&Path). This lets us pass additional builder parameters like the desired permissions. - The deprecated
TempDir::into_pathis removed in favor ofTempDir::keep. SpooledTempDir::newis now const.tempfile::env::temp_dir()now returns a result and won't panic on platforms wherestd::env::temp_dirwould panic.
TBD:
- [ ] https://github.com/Stebalien/tempfile/issues/40. I'd love to fix this but... I'd need to keep open a parent-directory file descriptor and I'd rather not do that if I don't have to. I should probably poke around and see what other temporary file libraries do.
- [ ] Prevent temporary file cleanup by taking a shared advisory locks on all named temporary files to prevent temporary file cleaners from deleting them. This could break some things so we have to be careful, but taking a shared lock is probably reasonable? Possibly only do this if the parent directory is
+t(sticky)? We can also make it configurable in the builder, the question will be: what's the default behavior?
Fixes:
- #59
- Everything in #258
~~One minor annoyance I noticed with TempDir::close is that you no longer have access to the path for error reporting, so it has to be copied beforehand.~~
edit: nvm I missed that this actually attaches the path to the error. Didn't realize you could do that and still return a std::io::Error
debian trixie has released with rust 1.85, though IIRC one of the other popular distro (centos or fedora, I can't remember) still on 1.84
though IIRC one of the other popular distro (centos or fedora, I can't remember) still on 1.84
Ah, that's good to know. I'll see if I can downgrade to that.
Also note, I'm still planing on maintaining v3 for the foreseeable future.
It's Ubuntu plucky. Which is unfortunately rules out 2024 edition unless I wait until October (although it might take that long anyways if I try to tackle the remaining TODOs).