Stebalien / tempfile

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

feat: Allow cloning of TempDir #243

Closed vincenzopalazzo closed 1 year ago

vincenzopalazzo commented 1 year ago

This commit enables the option to clone the TempDir object, allowing multiple structures to own their own instance.

It is common for a directory to be passed among multiple structures.

For example, during integration testing, there may be a scenario where two instances of a daemon are running simultaneously and accessing the disk. In such cases, the order of dropping the directory becomes irrelevant since it will be cleaned up at the end of the test anyway.

Stebalien commented 1 year ago

This would delete the temporary directory when the first instance is dropped which would be a significant footgun. The correct solution is to either:

  1. Put it in an Rc/Arc.
  2. Copy out the underlying path leaving the TempDir object in the main test function.
vincenzopalazzo commented 1 year ago

Yeah I see