tempfile icon indicating copy to clipboard operation
tempfile copied to clipboard

Confusing documentation: "The inner file will be deleted"

Open osa1 opened this issue 2 years ago • 2 comments

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?

osa1 avatar Dec 16 '22 07:12 osa1

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(())
}

fleetingbytes avatar Apr 15 '23 04:04 fleetingbytes

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.

Stebalien avatar Apr 15 '23 19:04 Stebalien