tempfile
A library for managing temporary files and directories.
3.27.0
754M downloads/mo
#97 most downloaded on crates.io
Stebalien/tempfile
What this package is like to depend on
Last release 5 months ago
11 Mar 2026
Release timing varies
gaps range from 2 weeks to 3 months
Most releases are documented
notes for 49 of 63 stable releases
3 versions withdrawn
withdrawn after publishing
11 years old
66 releases · first in 2015
6 releases in the last 12 months
see the full history below
Release timeline
66 releases · Apr 2015 to Mar 2026Releases
latest 60 of 66-
3.27.011 Mar 2026Release notes
Open source →This release adds
TempPath::try_from_pathand deprecatesTempPath::from_path.Prior to this release,
TempPath::from_pathmade no attempts to convert relative paths into absolute paths. The following code would have deleted the wrong file:let tmp_path = TempPath::from_path("foo") std::env::set_current_dir("/some/other/path").unwrap(); drop(tmp_path);Now:
TempPath::from_pathwill attempt to convert relative paths into absolute paths. However, this isn't always possible as we need to callstd::env::current_dir, which can fail. If we fail to convert the relative path to an absolute path, we simply keep the relative path.- The
TempPath::try_from_pathbehaves exactly likeTempPath::from_path, except that it returns an error if we fail to convert a relative path into an absolute path (or if the passed path is empty).
Neither function attempt to verify the existence of the file in question.
Thanks to @meng-xu-cs for reporting this issue.
-
3.26.024 Feb 2026Release notes
Open source →- Support
NamedTempFile::persiston RedoxOS (#393) (thanks to @Andy-Python-Programmer).
- Support
-
3.25.009 Feb 2026 -
3.24.023 Dec 2025Release notes
Open source →- Actually support WASIp2 without the nightly feature. This library is now feature complete on WASIp2 without any additional feature flags.
- Exclude CI scripts from the published crate.
-
3.23.023 Sep 2025 -
3.22.009 Sep 2025Release notes
Open source →- Updated
windows-sysrequirement to allow version 0.61.x - Remove
unstable-windows-keep-open-tempfilefeature.
- Updated
-
3.21.019 Aug 2025 -
3.20.011 May 2025Release notes
Open source →This release mostly unifies the behavior/capabilities around "keeping" temporary files:
- Rename
Builder::keep(bool)(via deprecation) toBuilder::disable_cleanup(bool)to make it clear that behaves differently fromNamedTempFile::keep(). The former disables automatic cleanup while the latter consumes theNamedTempFileobject entirely and unsets the "temporary file" attribute (on Windows). - Rename
TempDir::into_path(via deprecation) toTempDir::keepto mirrorNamedTempFile::keep. - Add
TempDir::disable_cleanup,NamedTempFile::disable_cleanup, andTempPath::disable_cleanupmaking it possible to disable automatic cleanup in-place after creating a temporary file/directory (equivalent to callingBuilder::disable_cleanupbefore creating the file/directory).
Additionally, it adds a few spooled temporary file features: git lo
- Add
SpooledTempFile::into_filefor turning aSpooledTempFileinto a regular unnamed temporary file, writing it to the backing storage ("rolling" it) if it was still stored in-memory. - Add
spooled_tempfile_inandSpooledTempFile::new_inmethods for creating spooled temporary files in a specific directory. This makes it possible to choose the backing device for your spooled temporary file which is rather important on Linux where the default temporary directory is likely backed by memory (defeating the entire point of having a spooled temporary file).
Finally, this release improves documentation, especially the top-level documentation explaining which temporary file type to use.
BREAKING for those with
deny(warnings):Builder::keepdeprecated in favor ofBuilder::disable_cleanup.TempDir::into_pathis deprecated in favor ofTempDir::keep.
- Rename
-
3.19.119 Mar 2025Release notes
Open source →- Don't unlink temporary files immediately on Windows (fixes #339). Unfortunately, this seemed to corrupt the file object (possibly a Windows kernel bug) in rare cases and isn't strictly speaking necessary.
-
3.19.014 Mar 2025Release notes
Open source →- Remove direct dependency on
cfg-if. It's still in the tree, but we didn't really need to use it in this crate. - Add an unstable feature (
unstable-windows-keep-open-tempfile) to test a potential fix to #339.
- Remove direct dependency on
-
3.18.006 Mar 2025Release notes
Open source →- Update
rustixto 1.0.0. - Make
NamedTempFile::persist_noclobberatomic on Apple operating systems. It's now atomic on MacOS, Windows, and Linux (depending on the OS version and filesystem used).
- Update
-
3.17.117 Feb 2025Release notes
Open source →- Fix build with
windows-sys0.52. Unfortunately, we have no CI for olderwindows-sysversions at the moment...
- Fix build with
-
3.17.016 Feb 2025Release notes
Open source →- Make sure to use absolute paths in when creating unnamed temporary files (avoids a small race in the "immediate unlink" logic) and in
Builder::make_in(when creating temporary files of arbitrary types). - Prevent a theoretical crash that could (maybe) happen when a temporary file is created from a drop function run in a TLS destructor. Nobody has actually reported a case of this happening in practice and I have been unable to create this scenario in a test.
- When reseeding with
getrandom, use platform (e.g., CPU) specific randomness sources where possible. - Clarify some documentation.
- Unlink unnamed temporary files on windows immediately when possible instead of waiting for the handle to be closed. We open files with "Unix" semantics, so this is generally possible.
- Make sure to use absolute paths in when creating unnamed temporary files (avoids a small race in the "immediate unlink" logic) and in
-
3.16.028 Jan 2025Release notes
Open source →- Update
getrandomto0.3.0(thanks to @paolobarbolini). - Allow
windows-sysversions0.59.xin addition to0.59.0(thanks @ErichDonGubler). - Improved security documentation (thanks to @n0toose for collaborating with me on this).
- Update
-
3.15.002 Jan 2025Release notes
Open source →Re-seed the per-thread RNG from system randomness when we repeatedly fail to create temporary files (#314). This resolves a potential DoS vector (#178) while avoiding
getrandomin the common case where it's necessary. The feature is optional but enabled by default via thegetrandomfeature.For libc-free builds, you'll either need to disable this feature or opt-in to a different
getrandombackend. -
3.14.008 Nov 2024 -
3.13.028 Sep 2024Release notes
Open source →- Add
with_suffixconstructors for easily creating new temporary files with a specific suffix (e.g., a specific file extension). Thanks to @Borgerr. - Update dependencies (fastrand & rustix).
- Add
-
3.12.006 Aug 2024Release notes
Open source →- Add a
keep(keep: bool)function to builder that suppresses delete-on-drop behavior (thanks to @RalfJung). - Update
windows-sysfrom 0.52 to 0.59.
- Add a
-
3.11.002 Aug 2024Release notes
Open source →- Add the ability to override the default temporary directory. This API shouldn't be used in general, but there are some cases where it's unavoidable.
-
3.10.126 Feb 2024Release notes
Open source →- Handle potential integer overflows in 32-bit systems when seeking/truncating "spooled" temporary files past 4GiB (2³²).
- Handle a theoretical 32-bit overflow when generating a temporary file name larger than 4GiB. Now it'll panic (on allocation failure) rather than silently succeeding due to wraparound.
Thanks to @stoeckmann for finding and fixing both of these issues.
-
3.10.005 Feb 2024Release notes
Open source →- Drop
redox_syscalldependency, we now userustixfor Redox. - Add
Builder::permissionsfor setting the permissions on temporary files and directories (thanks to @Byron). - Update rustix to 0.38.31.
- Update fastrand to 2.0.1.
- Drop
-
3.9.028 Dec 2023 -
3.8.126 Oct 2023Release notes
Open source →- Update rustix to fix a potential panic on
persist_noclobberon android. - Update redox_syscall to 0.4 (on redox).
- Fix some docs typos.
- Update rustix to fix a potential panic on
-
3.8.018 Aug 2023Release notes
Open source →- Added
with_prefixandwith_prefix_intoTempDirandNamedTempFileto make it easier to create temporary files/directories with nice prefixes. - Misc cleanups.
- Added
-
3.7.106 Aug 2023Release notes
Open source →- Tempfile builds on haiku again.
- Under the hood, we've switched from the unlinkat/linkat syscalls to the regular unlink/link syscalls where possible.
-
3.7.020 Jul 2023Release notes
Open source →BREAKING: This release updates the MSRV to 1.63. This isn't an API-breaking change (so no major release) but it's still a breaking change for some users.
- Update fastrand from 1.6 to 2.0
- Update rustix to 0.38
- Updates the MSRV to 1.63.
- Provide AsFd/AsRawFd on wasi.
-
3.6.006 Jun 2023Release notes
Open source →- Update windows-sys to 0.48.
- Update rustix min version to 0.37.11
- Forward some
NamedTempFileandSpooledTempFilemethods to the underlyingFileobject for better performance (especially vectorized writes, etc.). - Implement
AsFdandAsHandle. - Misc documentation fixes and code cleanups.
-
3.5.029 Mar 2023Release notes
Open source →- Update rustix from 0.36 to 0.37.1. This makes wasi work on rust stable
- Update
windows-sys,redox_syscall - BREAKING: Remove the implementation of
Write for &NamedTempFile<F> where &F: Write. Unfortunately, this can cause compile issues in unrelated code (https://github.com/Stebalien/tempfile/issues/224).
-
3.4.025 Feb 2023Release notes
Open source →SECURITY: Prior
tempfilereleases depended onremove_dir_allversion 0.5.0 which was vulnerable to a TOCTOU race. This same race is present in rust versions prior to 1.58.1.Features:
- Generalized temporary files:
NamedTempFilecan now abstract over different kinds of files (e.g., unix domain sockets, pipes, etc.):- Add
Builder::makeandBuilder::make_infor generalized temp file creation. - Add
NamedTempFile::from_partsto complementNamedTempFile::into_parts. - Add generic parameter to
NamedTempFileto support wrapping non-File types.
- Add
Bug Fixes/Improvements:
- Don't try to create a temporary file multiple times if the file path has been fully specified by the user (no random characters).
NamedTempFile::persist_noclobberis now always atomic on linux whenrenameat_withis supported. Previously, it would first link the new path, then unlink the previous path.- Fix compiler warnings on windows.
Trivia:
- Switch from
libctorustixon wasi/unix. This now makes direct syscalls instead of calling through libc. - Remove
remove_dir_alldependency. The rust standard library has optimized their internal version significantly. - Switch to official windows-sys windows bindings.
Breaking:
- The minimum rust version is now
1.48.0. - Mark most functions as
must_use. - Uses direct syscalls on linux by default, instead of libc.
- The new type parameter in
NamedTempFilemay lead to type inference issues in some cases.
- Generalized temporary files:
-
3.3.008 Jan 2022Release notes
Open source →Features:
- Replace rand with fastrand for a significantly smaller dependency tree. Cryptographic randomness isn't necessary for temporary file names, and isn't all that helpful either.
- Add limited WASI support.
- Add a function to extract the inner data from a
SpooledTempFile.
Bug Fixes:
- Make it possible to persist unnamed temporary files on linux by removing the
O_EXCLflag. - Fix redox minimum crate version.
-
3.2.012 Jan 2021Release notes
Open source →Features:
- Bump rand dependency to
0.8. - Bump cfg-if dependency to
1.0
Other than that, this release mostly includes small cleanups and simplifications.
Breaking: The minimum rust version is now
1.40.0. - Bump rand dependency to
-
3.1.001 Jul 2019Release notes
Open source →Features:
- Bump rand dependency to
0.7.
Breaking: The minimum rust version is now
1.32.0. - Bump rand dependency to
-
3.0.930 Jun 2019 withdrawnRelease notes
Open source →Documentation:
- Add an example for reopening a named temporary file.
- Flesh out the security documentation.
Features:
- Introduce an
appendoption to the builder. - Errors:
- No longer implement the soft-deprecated
description. - Implement
sourceinstead ofcause.
- No longer implement the soft-deprecated
Breaking: The minimum rust version is now 1.30.
-
3.0.819 May 2019Release notes
Open source →This is a bugfix release.
Fixes:
- Export
PathPersistError. - Fix a bug where flushing a
SpooledTempFileto disk could fail to write part of the file in some rare, yet-to-reproduced cases.
- Export
-
3.0.717 Feb 2019Release notes
Open source →Breaking:
Builder::prefixandBuilder::suffixnow accept a generic&AsRef<OsStr>. This could affect type inference.- Temporary files (except unnamed temporary files on Windows and Linux >= 3.11) now use absolute path names. This will break programs that create temporary files relative to their current working directory when they don't have the search permission (x) on some ancestor directory. This is only likely to affect programs with strange chroot-less filesystem sandboxes. If you believe you're affected by this issue, please comment on #40.
Features:
- Accept anything implementing
&AsRef<OsStr>in the builder: &OsStr, &OsString, &Path, etc.
Fixes:
- Fix LFS support.
- Use absolute paths for named temporary files to guard against changes in the current directory.
- Use absolute paths when creating unnamed temporary files on platforms that can't create unlinked or auto-deleted temporary files. This fixes a very unlikely race where the current directory could change while the temporary file is being created.
Misc:
- Use modern stdlib features to avoid custom unsafe code. This reduces the number of unsafe blocks from 12 to 4.
-
3.0.606 Feb 2019 -
3.0.526 Nov 2018Release notes
Open source →Features:
- Added a spooled temporary file implementation. This temporary file variant starts out as an in-memory temporary file but "rolls-over" onto disk when it grows over a specified size (#68).
- Errors are now annotated with paths to make debugging easier (#73).
Misc:
- The rand version has been bumped to 0.6 (#74).
Bugs:
- Tempfile compiles again on Redox (#75).
-
3.0.414 Sep 2018 -
3.0.317 Jul 2018 -
3.0.210 May 2018Release notes
Open source →- Actually delete temporary files on non-Linux unix systems (thanks to @oliverhenshaw for the fix and a test case).
-
3.0.118 Apr 2018 withdrawn -
3.0.025 Mar 2018 withdrawnRelease notes
Open source →- Adds temporary directory support (@KodrAus)
- Allow closing named temporary files without deleting them (@jasonwhite)
-
2.2.027 Sep 2017 -
2.1.616 Jul 2017 -
2.1.519 Jan 2017Release notes
Open source →- Don't build platform-specific dependencies on all platforms.
- Cleanup some documentation.
-
2.1.414 Jun 2016 -
2.1.321 Apr 2016 -
2.1.211 Apr 2016Release notes
Open source →Add
Read/Write/Seekimpls on&NamedTempFile. This mirrors the implementations on&File. One can currently just deref to a&Filebut these implementations are more discoverable. -
2.1.117 Feb 2016 -
2.1.011 Feb 2016Release notes
Open source →- Implement
AsRef<File>forNamedTempFileallowing named temporary files to be borrowed asFiles. - Add a method to convert a
NamedTempFileto an unnamed temporaryFile.
- Implement
-
2.0.118 Jan 2016 -
2.0.005 Jan 2016Release notes
Open source →This release replaces
TempFilewith atempfile()function that returnsstd::fs::Fileobjects. These are significantly more useful because most rust libraries expect normalFileobjects.To continue supporting shared temporary files, this new version adds a
reopen()method toNamedTempFile. -
1.1.321 Nov 2015Nothing published for this version
-
1.1.208 Nov 2015Nothing published for this version
-
1.1.115 Aug 2015Nothing published for this version
-
1.1.010 Jul 2015Nothing published for this version
-
1.0.029 Jun 2015Nothing published for this version
-
0.5.122 May 2015Nothing published for this version
-
0.5.022 May 2015Nothing published for this version
-
0.4.021 May 2015Nothing published for this version