tempfile
tempfile copied to clipboard
Confusing documentation: "The inner file will be deleted"
NamedTempFile::into_file says "The inner file will be deleted".
It's unclear what that means. I'm assuming it means the temp file will be deleted when the Rust File returned by into_file is dropped, but it could also mean that the file will be deleted immediately, but the file handle will still be usable (like in into_parts).
Could you clarify this please?
I tried it, the file is not deleted immediately.
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let t = tempfile::NamedTempFile::new()?;
let tpath = t.into_temp_path();
let path = tpath.to_path_buf();
assert!(path.is_file());
tpath.close()?;
assert!(!path.is_file());
Ok(())
}
Hm. Yeah, this needs to be improved. The idea was to downgrade a named temporary file into an unnamed temporary file where:
- On Linux, the file would get deleted immediately.
- On windows, the file should be marked for deletion on close. But we aren't doing that.