Expand description
temp-dir
Provides a TempDir struct.
Features
- Makes a directory in a system temporary directory
- Recursively deletes the directory and its contents on drop
- Deletes symbolic links and does not follow them.
- Optional name prefix
- Depends only on
std forbid(unsafe_code)- 100% test coverage
Limitations
- Not security-hardened. For example, directory and file names are predictable.
- This crate uses
std::fs::remove_dir_allwhich may be unreliable on Windows. See rust#29497 andremove_dir_allcrate.
Alternatives
tempfile- Popular and mature
- Contains
unsafe, dependencies full ofunsafe - Heavy dependencies (libc, winapi, rand, etc.)
test_dir- Has a handy
TestDirstruct - Incomplete documentation
- Has a handy
temp_testdir- Incomplete documentation
mktemp- Sets directory mode 0700 on unix
- Contains
unsafe - No readme or online docs
Related Crates
Example
use temp_dir::TempDir;
let d = TempDir::new().unwrap();
// Prints "/tmp/t1a9b-0".
println!("{:?}", d.path());
let f = d.child("file1");
// Prints "/tmp/t1a9b-0/file1".
println!("{:?}", f);
std::fs::write(&f, b"abc").unwrap();
assert_eq!(
"abc",
std::fs::read_to_string(&f).unwrap(),
);
// Prints "/tmp/t1a9b-1".
println!(
"{:?}", TempDir::new().unwrap().path());Cargo Geiger Safety Report
Changelog
- v0.1.11
- Return
std::io::Errorinstead ofString. - Add
cleanup.
- Return
- v0.1.10 - Implement
Eq,Ord,Hash - v0.1.9 - Increase test coverage
- v0.1.8 - Add
leak. - v0.1.7 - Update docs:
Warn about
std::fs::remove_dir_allbeing unreliable on Windows. Warn about predictable directory and file names. Thanks to Reddit user burntsushi. - v0.1.6 - Add
TempDir::panic_on_cleanup_error. Thanks to Reddit usersKhorneLordOfChaosanddpc_pwfor their comments. - v0.1.5 - Explain how it handles symbolic links. Thanks to Reddit user Mai4eeze for this idea.
- v0.1.4 - Update docs
- v0.1.3 - Minor code cleanup, update docs
- v0.1.2 - Update docs
- v0.1.1 - Fix license
- v0.1.0 - Initial version
Happy Contributors 🙂
Fixing bugs and adding features is easy and fast. Send us a pull request and we intend to:
- Always respond within 24 hours
- Provide clear & concrete feedback
- Immediately make a new release for your accepted change
Structs
The path of an existing writable directory in a system temporary directory.