Open bsj0006 opened 5 months ago
Tagging subscribers to this area: @dotnet/area-system-io See info in area-owners.md if you want to be subscribed.
Perhaps FileStream could just change the Exception.Message of the UnauthorizedAccessException to say that it's a directory, when it gets an EISDIR error from the operating system. Changing the type of the exception seems more risky.
I don't expect we can change the exception type, but perhaps a better error message is possible when a directory path is provided to open. Moving the suggestion to IO.
Tagging subscribers to this area: @dotnet/area-system-io See info in area-owners.md if you want to be subscribed.
We're open to suggestions for improving the exception message. Some IO APIs document this behavior e.g. File.Open, some don't (e.g. FileStream.ctors, although it should).
ZipFile.ExtractToDirectory could also lift the exception documentation, so it becomes clear for its users.
Description
If you mistakenly pass a directory as the sourceArchiveFileName parameter for ZipFile.ExtractToDirectory(), you receive an UnauthorizedAccessException.
Reproduction Steps
ZipFile.ExtractToDirectory("/temp/thisIsADirectory", "/temp/alsoADirectory")
Expected behavior
Based on the current docs, I would assume the exception would be a NotSupportedException or InvalidDataException with a message like "[sourceArchiveFileName] is not a valid zip archive".
Actual behavior
You get an UnauthorizedAccessException with the message "Access to the path '[sourceArchiveFileName]' is denied" regardless of permissions on the directory.
Regression?
.NET 8, 7, & 6
Known Workarounds
No response
Configuration
.NET 8 Windows 11 x64 and mcr.microsoft.com/dotnet/runtime:8.0 Docker image
Other information
No response