Skip to content

Add preCreate parameter to TempFile.Create() and TempDirectory.Create() - #35

Merged
Tyrrrz merged 12 commits into
primefrom
copilot/add-bool-parameter-for-pre-create
Apr 15, 2026
Merged

Tyrrrz merged 12 commits into
primefrom
copilot/add-bool-parameter-for-pre-create

Conversation

Copilot AI commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

TempFile.Create() and TempDirectory.Create() previously always created the file/directory on disk. This adds a preCreate parameter to both so callers can obtain a unique temp path without touching the filesystem.

  • TempFile.cs: Added bool preCreate = true to Create(). When false, skips file creation — only the path is generated. When true, uses FileStream with FileMode.CreateNew to avoid overwriting, retries with a fresh GUID on path collision (up to 20 attempts), and throws InvalidOperationException if all attempts are exhausted.
  • TempFileTests.cs: Added Create_WithoutPreCreate_Test covering the preCreate: false case.
  • TempDirectory.cs: Added bool preCreate = true to Create(). When false, skips directory creation — only the path is generated. When true, retries with a fresh GUID if the path already exists (up to 20 attempts), and throws InvalidOperationException if all attempts are exhausted.
  • TempDirectoryTests.cs: Added Create_WithoutPreCreate_Test covering the preCreate: false case.
// Path-only — file not created on disk
using var tempFile = TempFile.Create(preCreate: false);
File.Exists(tempFile.Path); // false

// Path-only — directory not created on disk
using var tempDir = TempDirectory.Create(preCreate: false);
Directory.Exists(tempDir.Path); // false

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 15, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review April 15, 2026 16:55
Copilot AI review requested due to automatic review settings April 15, 2026 16:55
@Tyrrrz

Tyrrrz commented Apr 15, 2026

Copy link
Copy Markdown
Owner

Let's do the same with TempDirectory @copilot

Copilot AI commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

Let's do the same with TempDirectory @copilot

Done in 6b6379a. TempDirectory.Create() now has the same bool preCreate = true parameter, and Create_WithoutPreCreate_Test covers the preCreate: false case.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an option to TempFile.Create() to return a unique temp file path without creating the file on disk, supporting scenarios where callers want a path reservation without filesystem writes.

Changes:

  • Extended TempFile.Create() with an optional preCreate parameter (default true) to control whether the file is created.
  • Added a unit test verifying the preCreate: false behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
PowerKit/TempFile.cs Adds preCreate parameter and conditional file creation logic in TempFile.Create().
PowerKit.Tests/TempFileTests.cs Adds test coverage for the new preCreate: false behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit/TempFile.cs Resolved
Comment thread PowerKit/TempFile.cs Resolved
Copilot AI changed the title Add preCreate parameter to TempFile.Create() Add preCreate parameter to TempFile.Create() and TempDirectory.Create() Apr 15, 2026
Copilot AI requested a review from Tyrrrz April 15, 2026 16:59
Comment thread PowerKit/TempDirectory.cs Resolved
Comment thread PowerKit/TempFile.cs Resolved
@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Comment thread PowerKit/TempDirectory.cs Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants