Skip to content

GH-4660: Implement GetFileSystemInfo in FileSystem, Directory and Glo… - #4704

Merged
devlead merged 1 commit into
cake-build:developfrom
Abde1rahman1:feature/get-filesystem-info
Sep 24, 2026
Merged

devlead merged 1 commit into
cake-build:developfrom
Abde1rahman1:feature/get-filesystem-info

Conversation

@Abde1rahman1

@Abde1rahman1 Abde1rahman1 commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR addresses #4660 by providing a way to retrieve file system entries (files and directories) without needing to know the type beforehand.
All additions are non-breaking: new interface members are default interface methods, and IGlobber is unchanged.

Changes

  • Added IFileSystem.GetFileSystemInfo(string path) and IFileSystem.GetFileSystemInfo(Path path) as default interface methods. They return an IDirectory when
    the path exists as a directory; otherwise an IFile (including when the path does not exist). The string overload lets callers like
    context.FileSystem.GetFileSystemInfo("./foo") compile without ambiguity.
  • Added IDirectory.GetFileSystemInfos(string filter, SearchScope scope) as a default interface method (directories, then files). Directory and FakeDirectory
    both use this single implementation.
  • Added GlobberExtensions.GetFileSystemInfos(this IGlobber, IFileSystem, GlobPattern[, GlobberSettings]), built on the existing IGlobber.Match.
  • Added the GetFileSystemInfos(pattern[, settings]) alias in Cake.Common (GlobbingAliases). This is the entry point for scripts and Frosting.

@Abde1rahman1

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Abde1rahman1

Copy link
Copy Markdown
Contributor Author

Any Updates here ?!

@devlead

devlead commented Feb 15, 2026

Copy link
Copy Markdown
Member

Any Updates here ?!

Thank you for your contribution and effort here! I see that this PR introduces GetFileSystemInfo on IFileSystem and related methods on IDirectory/IGlobber.

However, adding members directly to these core interfaces without a default implementation is a breaking change, which we'll need to consider carefully, as it may require a major release, as it potentially breaks ABI and any existing external dependency i.e., Cake addins.

There are also no tests verifying these changes (Cake.Core Unit tests are located https://github.com/cake-build/cake/tree/develop/src/Cake.Core.Tests, and integration tests are here). Which means we'll need to allocate time and resources to carefully review this PR; we will, but can't guarantee when.

@devlead devlead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for picking up #4660 — the direction is right (mixed file/directory entries without the caller knowing the type up front).

This still needs another pass before we can merge. Adding members directly to IFileSystem, IDirectory, and IGlobber without default implementations is a breaking ABI change for addins and fakes (already labeled). Cake already uses default interface methods on IDirectory for newer members; please follow that, and keep globbing helpers on extensions/aliases like GetFiles / GetDirectories.

There are also correctness bugs in Globber.GetFileSystemInfos (inverted case sensitivity vs Match, empty pattern NullReferenceException, missing Distinct), GetFileSystemInfo takes DirectoryPath so a file path cannot be passed, and there are no tests.

Requested changes

  1. Avoid a breaking change

    • IDirectory.GetFileSystemInfos: default implementation concatenating existing GetDirectories + GetFiles (place it next to those methods).
    • IFileSystem.GetFileSystemInfo: default implementation that probes directory then file (or overloads for FilePath / DirectoryPath / Path).
    • Do not add a member to IGlobber. Put GetFileSystemInfos on GlobberExtensions (and a Cake.Common alias if we want GetFileSystemInfos(pattern) in scripts), mapping Match results through IFileSystem.
  2. GetFileSystemInfo must accept a file or a directory

    • Issue #4660 is specifically “we don’t know the type.” DirectoryPath only cannot express a FilePath (no conversion). Prefer Path plus overloads if string conversion is ambiguous. If the path exists as a directory, return IDirectory; otherwise return IFile (including non-existent — please document that).
  3. Globber must match Match / GetFiles

    • Reuse Match (or the same empty-pattern, parse, walk, Distinct(_comparer), and default case-sensitivity handling). Do not invert IsCaseSensitive. Take GlobPattern + GlobberSettings like the rest of the globber API. Drop the unused _fileSystem field if it is not needed.
  4. Tests (currently none)

    • Unit: src/Cake.Core.Tests — GetFileSystemInfo (file exists, directory exists, neither, null); globber beside GlobberTests (empty pattern, case sensitivity vs Match, mixed files+dirs, settings/predicates).
    • Fake: src/Cake.Testing.Tests Verify tests next to existing GetFiles / GetDirectories cases.
    • Integration (required): tests/integration is how we prove .cake scripts still compile and run. Existing GetFiles / GetDirectories / GetPaths tasks in tests/integration/Cake.Common/IO/GlobbingAliases.cake must still pass. Also add script tests for Context.FileSystem.GetFileSystemInfo, directory.GetFileSystemInfos, and Context.Globber.GetFileSystemInfos / a GetFileSystemInfos alias, wired into the same aggregator tasks in tests/integration/build.cake.

Nit: please remove the non-English comment in FakeDirectory.GetFileSystemInfos.

Comment thread src/Cake.Core/IO/IFileSystem.cs Resolved
Comment thread src/Cake.Core/IO/IDirectory.cs Resolved
Comment thread src/Cake.Core/IO/IGlobber.cs Resolved
Comment thread src/Cake.Core/IO/Globber.cs Resolved
Comment thread src/Cake.Core/IO/FileSystem.cs Resolved
Comment thread src/Cake.Testing/FakeDirectory.cs Resolved
@Abde1rahman1

Copy link
Copy Markdown
Contributor Author

Thanks @devlead for the detailed review — I've pushed a new commit addressing all of it.
Avoided the breaking change

  • IDirectory.GetFileSystemInfos is now a default interface implementation next to GetDirectories/GetFiles, concatenating the two.
  • IFileSystem.GetFileSystemInfo is now a default implementation that probes directory-then-file.
  • Removed GetFileSystemInfos from IGlobber entirely. It now lives on GlobberExtensions (mapping Match results through
    IFileSystem.GetDirectory/GetFile), plus a GetFileSystemInfos alias on ICakeContext in Cake.Common so it's usable from scripts.

GetFileSystemInfo now accepts file or directory

  • Signature changed to take Path (so both FilePath and DirectoryPath work). It returns IDirectory if the path exists as a directory,
    otherwise IFile — including for non-existent paths, which is documented on the member.

Globber correctness

  • GetFileSystemInfos (on GlobberExtensions now) reuses Match directly instead of re-implementing parse/walk, so it inherits the same
    empty-pattern handling, Distinct(_comparer), and default case sensitivity — the inverted IsCaseSensitive bug is gone.
  • Dropped the unused _fileSystem field from Globber.

Tests

  • Unit: added FileSystemTests covering GetFileSystemInfo (file, directory, missing, null path), and a TheGetFileSystemInfosMethod block
    in GlobberTests covering empty pattern, case sensitivity vs Match, mixed files+directories, and settings/predicates.
  • Fake: updated FakeFileSystemTests.FakeDirectory and removed the bespoke FakeDirectory/FakeFileSystem overrides in favor of the default interface implementations (so the fakes now exercise the same code path as real usage).
  • Integration: added GetFileSystemInfo/GetFileSystemInfos tasks to tests/integration/Cake.Common/IO/GlobbingAliases.cake, wired into the Cake.Common.IO.GlobbingAliases aggregator, covering Context.FileSystem.GetFileSystemInfo, directory.GetFileSystemInfos, and the
    Context.Globber/alias path. Existing GetFiles/GetDirectories/GetPaths tasks are untouched and still pass.

Nit

  • Removed the non-English comment in FakeDirectory (the method itself is gone now, replaced by the default interface implementation).

@devlead devlead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the follow-up — the DIM / extensions / tests pass addresses most of the previous review.

IDirectory.GetFileSystemInfos and IFileSystem.GetFileSystemInfo are now default interface methods, IGlobber is unchanged, globbing goes through GlobberExtensions + the Cake.Common alias, Match is reused, and there are unit, Fake Verify, and integration tests. That is the right shape for a non-breaking add.

This still is not merge-ready because GetFileSystemInfo(Path) cannot be called with a string. FilePath and DirectoryPath both have implicit string conversions, so context.FileSystem.GetFileSystemInfo("./foo") is ambiguous — which is exactly the #4660 case (the caller does not know the type). Typed FilePath/DirectoryPath tests do not cover that.

Requested changes

  1. Add a GetFileSystemInfo(string path) default implementation (same directory-then-file probe). Keep the Path overload. Optional FilePath/DirectoryPath overloads do not fix strings by themselves. Add a unit test and an integration assertion that pass a string.
  2. Delete the copy of GetFileSystemInfos on internal Directory so the interface default is the only implementation (same as FakeDirectory).
  3. Revert whitespace-only changes (IGlobber.cs, FileSystem.cs, FakeDirectory.cs, FakeFileSystem.cs, extra blanks / missing EOF newlines).
  4. Update the PR description (it still says members were added to IGlobber and the fakes).

Nits: license header + Given/When/Then on FileSystemTests; ArgumentNullException.ThrowIfNull on the DIM; an <example> on the alias like GetFiles. Script callers should use GetFileSystemInfos(pattern); Core IGlobber should not grow a member.

The Breaking change label can come off once the string overload exists. Please do not add anything back onto IGlobber.

Comment thread src/Cake.Core/IO/IFileSystem.cs Resolved
Comment thread src/Cake.Core/IO/Directory.cs Resolved
Comment thread src/Cake.Core/IO/GlobberExtensions.cs Resolved
Comment thread src/Cake.Core/IO/IGlobber.cs Resolved
@Abde1rahman1

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, @devlead All requested changes are addressed:

  • String overload: added GetFileSystemInfo(string path) as a default interface method with the same directory-then-file probe. The Path overload is kept and delegates to it, so context.FileSystem.GetFileSystemInfo("./foo") now compiles.
  • Tests: added unit tests that pass a string (file exists, directory exists, missing, null), plus integration assertions in GlobbingAliases.cake that use
    string paths.
  • Single implementation: removed the GetFileSystemInfos copy from the internal Directory, so Directory and FakeDirectory both use the IDirectory
    default.
  • Whitespace: reverted IGlobber.cs, FileSystem.cs, FakeDirectory.cs, and FakeFileSystem.cs. They're no longer in the diff.
  • IGlobber: unchanged. Nothing was added back.
  • Nits: license header and Given/When/Then on FileSystemTests, ArgumentNullException.ThrowIfNull in the default methods, and <example> blocks on the
    GetFileSystemInfos aliases. The Core GlobberExtensions docs now point script and Frosting callers to the GetFileSystemInfos(pattern) alias.
  • PR description: updated to match the current implementation.

Since the string overload is in, could the "Breaking change" label be removed? Let me know if anything else needs adjusting.

@devlead devlead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM👍 Will merge once CI passes.

@devlead
devlead merged commit 4a53e33 into cake-build:develop Sep 24, 2026
18 checks passed
@devlead

devlead commented Sep 24, 2026

Copy link
Copy Markdown
Member

@Abde1rahman1 your changes have been merged, thanks for your contribution 👍

@Abde1rahman1

Copy link
Copy Markdown
Contributor Author

Thanks a lot, @devlead Really enjoyed contributing to Cake and learned a lot from your review. Looking forward to making more contributions!

kubaflo added a commit to dotnet/maui that referenced this pull request Nov 26, 2026
Updated [cake.tool](https://github.com/cake-build/cake) from 6.3.0 to
7.0.0.

<details>
<summary>Release notes</summary>

_Sourced from [cake.tool's
releases](https://github.com/cake-build/cake/releases)._

## 7.0.0

As part of this release we had [106
issues](https://github.com/cake-build/cake/milestone/98?closed=1)
closed.



__Breaking changes__

- [__#​2835__](cake-build/cake#2835) Migrate
Cake.Tool from Autofac to Microsoft.Extensions.DependencyInjection by
[patriksvensson](https://github.com/patriksvensson) resolved in
[__!5010__](cake-build/cake#5010) by
[devlead](https://github.com/devlead)
- [__#​4997__](cake-build/cake#4997) Remove
Unsupported TFMS .NET 8 & 9 (net8.0 & net9.0) by
[devlead](https://github.com/devlead) resolved in
[__!5045__](cake-build/cake#5045) by
[devlead](https://github.com/devlead)
- [__#​5001__](cake-build/cake#5001) Update
LatestPotentialBreakingChange to 7.0.0 by
[devlead](https://github.com/devlead) resolved in
[__!5012__](cake-build/cake#5012) by
[devlead](https://github.com/devlead)
- [__#​5003__](cake-build/cake#5003) Remove
obsolete members / methods by [devlead](https://github.com/devlead)
resolved in [__!5012__](cake-build/cake#5012) by
[devlead](https://github.com/devlead)
- [__#​5060__](cake-build/cake#5060) Make
unified dependency graph the default when running multiple targets by
[devlead](https://github.com/devlead) resolved in
[__!5061__](cake-build/cake#5061) by
[devlead](https://github.com/devlead)
- [__#​5079__](cake-build/cake#5079) Update
Spectre.Console.Cli to 0.57.2 by [devlead](https://github.com/devlead)
resolved in [__!5080__](cake-build/cake#5080) by
[devlead](https://github.com/devlead)
- [__#​5169__](cake-build/cake#5169) Make
environment-defaulted DotNet switches tri-state to allow explicit
opt-out by [devlead](https://github.com/devlead) resolved in
[__!5170__](cake-build/cake#5170) by
[devlead](https://github.com/devlead)

__Bugs__

- [__#​2646__](cake-build/cake#2646) Incorrect
translation of literal constants used as optional parameter values (when
constants are defined in a separate file) by
[Meertman](https://github.com/Meertman) resolved in
[__!5017__](cake-build/cake#5017) by
[devlead](https://github.com/devlead)
- [__#​3829__](cake-build/cake#3829) Error:
Error getting value from 'CurrentUser' on
'Cake.Core.IO.WindowsRegistry'. by
[vCillusion](https://github.com/vCillusion) resolved in
[__!4802__](cake-build/cake#4802) by
[wyf027](https://github.com/wyf027),
[__!5011__](cake-build/cake#5011) by
[Samyra312007](https://github.com/Samyra312007)
- [__#​3830__](cake-build/cake#3830)
[Cake.Frosting] has exit code -1 for any kind of error by
[juwens](https://github.com/juwens) resolved in
[__!3831__](cake-build/cake#3831) by
[juwens](https://github.com/juwens),
[__!5015__](cake-build/cake#5015) by
[devlead](https://github.com/devlead)
- [__#​5095__](cake-build/cake#5095) Fix Unix
GetSpecialPath HOME and Program Files mapping by
[devlead](https://github.com/devlead) resolved in
[__!5096__](cake-build/cake#5096) by
[devlead](https://github.com/devlead)
- [__#​5155__](cake-build/cake#5155)
Interpolated strings bind to string log overloads instead of
FormattableString overloads by [devlead](https://github.com/devlead)
resolved in [__!5156__](cake-build/cake#5156) by
[devlead](https://github.com/devlead)
- [__#​5157__](cake-build/cake#5157) Using
declarations without parentheses on the first line are hoisted as using
alias directives by [devlead](https://github.com/devlead) resolved in
[__!5158__](cake-build/cake#5158) by
[devlead](https://github.com/devlead)

__Documentation__

- [__#​5024__](cake-build/cake#5024) Add Cake
DSL examples to BuildSystem and CI provider APIs by
[devlead](https://github.com/devlead) resolved in
[__!5025__](cake-build/cake#5025) by
[devlead](https://github.com/devlead)
- [__#​5026__](cake-build/cake#5026) Add a
Cake DSL example to GetCallerInfo by
[devlead](https://github.com/devlead) resolved in
[__!5027__](cake-build/cake#5027) by
[devlead](https://github.com/devlead)
- [__#​5028__](cake-build/cake#5028) Add Cake
DSL examples to Task, Does, and CakeTaskBuilder by
[devlead](https://github.com/devlead) resolved in
[__!5029__](cake-build/cake#5029) by
[devlead](https://github.com/devlead)
- [__#​5030__](cake-build/cake#5030) Add Cake
DSL examples to ICakeContext, IFileSystem, ProcessArgumentBuilder, and
ToolSettings by [devlead](https://github.com/devlead) resolved in
[__!5031__](cake-build/cake#5031) by
[devlead](https://github.com/devlead)

__Features__

- [__#​1269__](cake-build/cake#1269) Request
for Task.Tool("nuget:?package=etc") by [jnm2](https://github.com/jnm2)
- [__#​2471__](cake-build/cake#2471) Install a
nuget tool on demand by [Roemer](https://github.com/Roemer) resolved in
[__!5009__](cake-build/cake#5009) by
[devlead](https://github.com/devlead)
- [__#​4660__](cake-build/cake#4660) Consider
adding IFileSystemInfo returning APIs in addition to IFile and
IDirectory by [paulomorgado](https://github.com/paulomorgado) resolved
in [__!4704__](cake-build/cake#4704) by
[Abde1rahman1](https://github.com/Abde1rahman1)
- [__#​4998__](cake-build/cake#4998) Add .NET
11 (net11.0) TFM by [devlead](https://github.com/devlead) resolved in
[__!5044__](cake-build/cake#5044) by
[devlead](https://github.com/devlead)
- [__#​4999__](cake-build/cake#4999) C# 15
Scripting Support by [devlead](https://github.com/devlead) resolved in
[__!5046__](cake-build/cake#5046) by
[devlead](https://github.com/devlead)
- [__#​5066__](cake-build/cake#5066) Drop dead
runtime checks and Task.Run wrappers by
[devlead](https://github.com/devlead) resolved in
[__!5067__](cake-build/cake#5067) by
[devlead](https://github.com/devlead)
- [__#​5070__](cake-build/cake#5070) Add
GitHub Actions AzureLogin for OIDC by
[devlead](https://github.com/devlead) resolved in
[__!5071__](cake-build/cake#5071) by
[devlead](https://github.com/devlead)
- [__#​5081__](cake-build/cake#5081) Add IFile
content read/write extensions aligned with System.IO.File by
[devlead](https://github.com/devlead) resolved in
[__!5082__](cake-build/cake#5082) by
[devlead](https://github.com/devlead)
- [__#​5085__](cake-build/cake#5085) Add
opt-in .NET 11 Process API support to Cake by
[devlead](https://github.com/devlead) resolved in
[__!5086__](cake-build/cake#5086) by
[devlead](https://github.com/devlead)
- [__#​5087__](cake-build/cake#5087) Add Tar
and Untar aliases for creating and extracting tar archives by
[devlead](https://github.com/devlead) resolved in
[__!5088__](cake-build/cake#5088) by
[devlead](https://github.com/devlead)
- [__#​5089__](cake-build/cake#5089) Add
DotNetUpdatePackage aliases for dotnet package update by
[devlead](https://github.com/devlead) resolved in
[__!5090__](cake-build/cake#5090) by
[devlead](https://github.com/devlead)
- [__#​5103__](cake-build/cake#5103) Add
DotNetDownloadPackage aliases for dotnet package download by
[devlead](https://github.com/devlead) resolved in
[__!5104__](cake-build/cake#5104) by
[devlead](https://github.com/devlead)
- [__#​5105__](cake-build/cake#5105) Add
DotNetSlnMigrate aliases for sln to slnx by
[devlead](https://github.com/devlead) resolved in
[__!5106__](cake-build/cake#5106) by
[devlead](https://github.com/devlead)
- [__#​5107__](cake-build/cake#5107) Add
DotNetProjectConvert aliases for file-based apps by
[devlead](https://github.com/devlead) resolved in
[__!5108__](cake-build/cake#5108) by
[devlead](https://github.com/devlead)
- [__#​5109__](cake-build/cake#5109) Add
DotNetNuGetWhy aliases for package dependency graphs by
[devlead](https://github.com/devlead) resolved in
[__!5111__](cake-build/cake#5111) by
[devlead](https://github.com/devlead)
- [__#​5112__](cake-build/cake#5112) Add
DotNetNuGetLocalsList and Clear aliases by
[devlead](https://github.com/devlead) resolved in
[__!5113__](cake-build/cake#5113) by
[devlead](https://github.com/devlead)
- [__#​5115__](cake-build/cake#5115) Add .NET
11 DotNetRun settings (environment, file, device, artifacts-path,
no-cache) by [devlead](https://github.com/devlead) resolved in
[__!5116__](cake-build/cake#5116) by
[devlead](https://github.com/devlead)
- [__#​5125__](cake-build/cake#5125) Add
ProcessSettings.StandardInput for StartProcess by
[devlead](https://github.com/devlead) resolved in
[__!5126__](cake-build/cake#5126) by
[devlead](https://github.com/devlead)
 ... (truncated)

Commits viewable in [compare
view](cake-build/cake@v6.3.0...v7.0.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cake.tool&package-manager=nuget&previous-version=6.3.0&new-version=7.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding IFileSystemInfo returning APIs in addition to IFile and IDirectory

2 participants