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

feat: Add clippy rule to avoid wrong usage of tempfile crate #2836

Closed
wants to merge 2 commits into from

Conversation

sarutak
Copy link
Member

@sarutak sarutak commented Aug 9, 2023

Related issue: #2835

I added tempfile crate in #2823 .
One pitfall is the usage of TempDir::into_path.
According to the API doc, TempDir::into_path leads the corresponding temporary directory not deleted automatically.
To avoid resource leak I proposes to add a clippy rule.

# specific language governing permissions and limitations
# under the License.

disallowed-methods = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer fix this instead of adding new clippy rules. Maybe we can call tempfile.close() by hand?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's difficult to change the behavior of TempDir::into_path because it's not a bug. It's a specification.
We can delete manually by fs::remove_dir_all (tempfile.close doesn't delete once TempDir::into_path is called) but my concern is the case someone can forget to delete by hand.
If someone don't know the behavior of TempDir::into_path, it can happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing the information! I would like to refactor current test logic so that we don't need to create tempfile any more, thus we also don't need to add clippy rules here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O.K. I see.

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

Successfully merging this pull request may close these issues.

2 participants