Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
osa1 opened this issue Dec 16, 2022 · 2 comments
Open

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

osa1 opened this issue Dec 16, 2022 · 2 comments

Comments

@osa1
Copy link

osa1 commented Dec 16, 2022

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
Copy link

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants