Skip to content

Add Directory.Copy extension method#38

Merged
Tyrrrz merged 17 commits intoprimefrom
copilot/add-powerkit-package-and-update-utilities
Apr 16, 2026
Merged

Add Directory.Copy extension method#38
Tyrrrz merged 17 commits intoprimefrom
copilot/add-powerkit-package-and-update-utilities

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

Ports Directory.Copy from Onova's DirectoryEx into PowerKit's DirectoryExtensions.

Changes

  • Directory.Packages.props — updates PolyShim to 2.10.0 to gain portable File.GetUnixFileMode / File.SetUnixFileMode polyfills for net35 and netstandard2.0

  • DirectoryExtensions.cs — adds Directory.Copy(sourcePath, destinationPath, overwrite = true):

    • Pre-creates all destination directories (including empty subdirectories) before opening any file streams
    • Opens destination files with exclusive locks before writing; concurrent readers may be blocked or fail with a sharing violation
    • Truncates destination files that are longer than their source counterpart
    • Preserves Unix file permissions on non-Windows platforms via File.GetUnixFileMode / File.SetUnixFileMode
    • Adapted for PowerKit's netstandard2.0 / net35 / net10.0 targets: replaces Path.GetRelativePath (NS2.1+) with a Substring approach; uses Disposable.Merge([.. sourceStreams, .. destinationStreams]).Dispose() in a finally block for safe stream disposal; uses File.OpenRead / File.OpenWrite / File.Open(FileMode.CreateNew) and a foreach/Zip loop
  • DirectoryExtensionsTests.cs — 6 new tests covering flat copy, nested subdirectory copy, overwrite, no-overwrite (IOException), destination truncation, and Unix file mode preservation (skipped on Windows)

Directory.Copy(sourcePath, destinationPath);
Directory.Copy(sourcePath, destinationPath, overwrite: false); // throws IOException if file exists

Copilot AI and others added 2 commits April 16, 2026 15:07
Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/509167ff-4a8d-42e8-8185-a209edb609b5

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

Tyrrrz commented Apr 16, 2026

@copilot we should also preserve Unix file modes. Update PolyShim to 2.10.0 in order to gain access to a portable implementation of File.Get/SetUnixMode().

…tory.Copy

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/67959c43-13cc-41de-973e-d36d89b21152

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

Copilot AI commented Apr 16, 2026

@copilot we should also preserve Unix file modes. Update PolyShim to 2.10.0 in order to gain access to a portable implementation of File.Get/SetUnixMode().

Done in f091558. Updated PolyShim to 2.10.0 and added Unix file mode preservation in the copy loop via File.GetUnixFileMode/File.SetUnixFileMode, guarded by !OperatingSystem.IsWindows(). Also added a Copy_UnixFileMode_Test that's skipped on Windows (via [SkippableFact] + Skip.If(OperatingSystem.IsWindows())).

@Tyrrrz Tyrrrz marked this pull request as ready for review April 16, 2026 18:44
Copilot AI review requested due to automatic review settings April 16, 2026 18:44
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.47%. Comparing base (431e52d) to head (f2e0129).
⚠️ Report is 1 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #38      +/-   ##
==========================================
+ Coverage   94.08%   94.47%   +0.39%     
==========================================
  Files          76       76              
  Lines        1470     1574     +104     
  Branches      125      131       +6     
==========================================
+ Hits         1383     1487     +104     
  Misses         65       65              
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
Comment thread PowerKit.Tests/DirectoryExtensionsTests.cs Outdated
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 16, 2026

@copilot run dotnet build to reformat everything

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot run dotnet build to reformat everything

Done in 9b53bb3. CSharpier reformatted DirectoryExtensionsTests.cs and the build now succeeds cleanly.

Comment thread PowerKit/Extensions/DirectoryExtensions.cs Outdated
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

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


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

Comment thread PowerKit/Extensions/DirectoryExtensions.cs
Comment thread PowerKit/Extensions/DirectoryExtensions.cs
Comment thread PowerKit/Extensions/DirectoryExtensions.cs
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