Stebalien / tempfile

Temporary file library for rust
http://stebalien.com/projects/tempfile-rs
Apache License 2.0
1.15k stars 113 forks source link

Confusing documentation: "The inner file will be deleted" #203

Open osa1 opened 1 year ago

osa1 commented 1 year ago

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?

fleetingbytes commented 1 year ago

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(())
}
Stebalien commented 1 year ago

Hm. Yeah, this needs to be improved. The idea was to downgrade a named temporary file into an unnamed temporary file where:

  1. On Linux, the file would get deleted immediately.
  2. On windows, the file should be marked for deletion on close. But we aren't doing that.