Skip to content

Add TempFile and TempDirectory utilities#11

Merged
Tyrrrz merged 11 commits intoprimefrom
copilot/implement-tempfile-and-tempdirectory
Apr 12, 2026
Merged

Add TempFile and TempDirectory utilities#11
Tyrrrz merged 11 commits intoprimefrom
copilot/implement-tempfile-and-tempdirectory

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Adds TempFile and TempDirectoryIDisposable wrappers that create uniquely-named resources under the system temp path and delete them on disposal.

  • PowerKit/TempFile.cs — partial class; Create() generates a GUID-based .tmp path under Path.GetTempPath() and creates the file via File.Create; Dispose() deletes it (idempotent — File.Delete does not throw when the file is absent)
  • PowerKit/TempDirectory.cs — same pattern; Create() generates and materializes a unique subdirectory; Dispose() recursively deletes it, suppressing DirectoryNotFoundException
using var file = TempFile.Create();
File.WriteAllText(file.Path, "hello");

using var dir = TempDirectory.Create();
File.Copy(file.Path, Path.Combine(dir.Path, "copy.txt"));
// Both cleaned up automatically on disposal

Modeled after the CliWrap test utilities of the same name, adapted for general-purpose library use.

Copilot AI and others added 2 commits April 12, 2026 15:18
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/ede74fd2-7b74-4470-bcfb-01606d5fc956

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 12, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 12, 2026 16:12
Copilot AI review requested due to automatic review settings April 12, 2026 16:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds disposable helpers for managing temp-file and temp-directory lifetimes in PowerKit, with accompanying tests to validate basic creation/cleanup behavior.

Changes:

  • Introduces TempFile and TempDirectory disposable wrappers under PowerKit/.
  • Adds xUnit test coverage for temp file/directory creation and disposal.
  • Implements directory materialization on create and recursive cleanup on dispose.

Reviewed changes

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

File Description
PowerKit/TempFile.cs Adds TempFile wrapper + factory method for generating a temp .tmp path and deleting it on dispose.
PowerKit/TempDirectory.cs Adds TempDirectory wrapper + factory method that creates a unique temp directory and deletes it on dispose.
PowerKit.Tests/TempFileTests.cs Adds tests for TempFile create/dispose behavior.
PowerKit.Tests/TempDirectoryTests.cs Adds tests for TempDirectory create/dispose behavior.

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

Comment thread PowerKit/TempFile.cs Outdated
Comment thread PowerKit/TempFile.cs Outdated
Comment thread PowerKit/TempFile.cs Outdated
Comment thread PowerKit/TempDirectory.cs
Comment thread PowerKit.Tests/TempFileTests.cs
Comment thread PowerKit.Tests/TempFileTests.cs
Tyrrrz and others added 4 commits April 12, 2026 19:17
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Dispose_AlreadyDeleted_Test

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/ed7674be-23ff-4044-a7a9-f1a4f6aee3a7

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 12, 2026

@copilot if there are of our own tests that could benefit from TempFile/TempDirectory, apply the necessary changes

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 12, 2026

@copilot if there are of our own tests that could benefit from TempFile/TempDirectory, apply the necessary changes

After reviewing all existing test files, none of them create or manage real temp files/directories on disk — they all use in-memory alternatives (MemoryStream, StringReader, etc.). There are no existing tests that would benefit from TempFile/TempDirectory.

Comment thread PowerKit.Tests/TempDirectoryTests.cs Outdated
Comment thread PowerKit.Tests/TempFileTests.cs Outdated
Comment thread PowerKit/TempFile.cs Outdated
Comment thread PowerKit/TempFile.cs Outdated
…try loop in Create

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/c02e964b-3b92-4d67-b1d6-196fcef9031d

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 12, 2026

@copilot please fix failing test

… resolve naming collision with Path property

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/3d364d09-b7bd-4e37-ade5-27b94d7e91a3

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 12, 2026

@copilot please fix failing test

Fixed in a9c01eb. The simplification of Create() introduced a compile error: without the FQNs, Path inside the partial class resolves to the instance property TempFile.Path rather than System.IO.Path. Restored System.IO.Path.* FQNs in the static method — this is the correct approach since there's a genuine naming collision.

Copilot AI requested a review from Tyrrrz April 12, 2026 16:48
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