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

[Breaking change]: drive's current directory paths used for file system entry enumeration return paths without a separator in between #39186

Closed
1 of 3 tasks
jozkee opened this issue Jan 17, 2024 · 1 comment · Fixed by #39487
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 8 Work items for the .NET 8 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@jozkee
Copy link
Member

jozkee commented Jan 17, 2024

Description

File system entries obtained using a path argument in the shape of a "drive's current directory" e.g. C: were incorrectly formed by combining directory path + separator + entry name. We now avoid adding the separator with such paths to return the correct path for the entries.

Version

.NET 8 GA

Previous behavior

string pathToEnumerate = "C:";

Console.WriteLine($"Full path of \"{pathToEnumerate}\" is {Path.GetFullPath(pathToEnumerate)}.");
Path.GetFullPath(pathToEnumerate);

Console.WriteLine($"Enumerating files and folders in \"{pathToEnumerate}\".");
foreach (string entry in Directory.GetFileSystemEntries(pathToEnumerate))
{
    Console.WriteLine(entry);
}

// Output
/*
Full path of "C:" is C:\Users\dacantu\consoleapps\Program

Enumerating files and folders in "C:".
C:\Program.csproj
C:\Program.sln
C:\bin
C:\obj
C:\Program.cs
*/

Notice the enumerated entries are shown as if they were in the drive's root.

New behavior

Using above code snippet, the output for .NET 9 is the following.

Full path of "C:" is C:\Users\dacantu\consoleapps\Program.

Enumerating files and folders in "C:".
C:Program.csproj
C:Program.sln
C:bin
C:obj
C:Program.cs

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

Users were reporting that this behavior was not correct, and it was also a regression from .NET Framework.

Recommended action

Windows users relying on enumeration of paths like C: should re-evaluate their application's IO operations. IMO, this is an unusual scenario unlikely to be used in production. Most users wanting to enumerate the current directory would use Environment.CurrentDirectory instead.

Feature area

Core .NET libraries

Affected APIs

System.IO.Directory.EnumerateFiles*
System.IO.Directory.EnumerateDirectories*
System.IO.Directory.EnumerateFileSystemEntries*
System.IO.Directory.GetFiles*
System.IO.Directory.GetDirectories*
System.IO.Directory.GetFileSystemEntries*
System.IO.DirectoryInfo.EnumerateFiles*
System.IO.DirectoryInfo.EnumerateDirectories*
System.IO.DirectoryInfo.EnumerateFileSystemEntries*
System.IO.DirectoryInfo.GetFiles*
System.IO.DirectoryInfo.GetDirectories*
System.IO.DirectoryInfo.GetFileSystemEntries*
System.IO.Enumeration.FileSystemEnumerable<TResult>.ctor(string, FileSystemEnumerable<TResult>.FindTransform transform, EnumerationOptions?)

Associated WorkItem - 206388

@jozkee jozkee added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Jan 17, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jan 17, 2024
@jozkee
Copy link
Member Author

jozkee commented Jan 19, 2024

@gewarren I've updated the Affected APIs to include Directory[Info].Enumerate*.

@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Feb 2, 2024
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Feb 2, 2024
@gewarren gewarren added 🏁 Release: .NET 8 Work items for the .NET 8 release and removed ⌚ Not Triaged Not triaged labels Feb 9, 2024
@dotnet-policy-service dotnet-policy-service bot added in-pr This issue will be closed (fixed) by an active pull request. labels Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 8 Work items for the .NET 8 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants