Stebalien / tempfile

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

FILE_FLAG_DELETE_ON_CLOSE isn't possible to have set on named tempfiles #277

Open bwoebi opened 8 months ago

bwoebi commented 8 months ago

It would be great it if it were possible to have some API where I can pass a prefix / name ending up with a self-deleting temp file.

I suppose for most use cases this doesn't matter, but I tried to use a well-known prefix, for two reasons:

a) finding the file in Resource Monitor for debugging b) naming a temporary executable so that it can be trivially identified in task manager.

Stebalien commented 8 months ago

This would likely mean two functions:

  1. tempfile_with_prefix
  2. tempfile_with_prefix_in

It's not truly cross-platform as the prefix would make no sense on Linux, but I'm open to it as long as we document that fact. As you say, this is only for debugging anyways.

dwattttt commented 7 months ago

I'll also chime in here with a use case; I'm using a tempfile to hold downloaded data that's then processed by an external tool, wiping the file/data after it's done. The problem is that the external tool does detection based on the file's suffix, so I have to lose FILE_FLAG_DELETE_ON_CLOSE (or as a workaround use a common filename in a temp dir).