-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
ZipFile.ExtractToDirectory doc comments wrongly claim that the directory must not exist #95501
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionThe documentation comments of the
and
Additionally,
and
Looking through the source code, most of the statements don't seem to be true and it seems totally fine to provide a directory path that either exists or doesn't. That's because those methods call // in ZipFileExtensions.ZipArchiveEntry.Extract.cs:
// Note that this will give us a good DirectoryInfo even if destinationDirectoryName exists:
DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName); Reproduction Steps// case 1: specified path does not exist
string dir1 = @"C:\temp\some1\path1";
ZipFile.ExtractToDirectory(@"C:\temp\some.zip", dir1); // works, but according to the docs should not (because parent dir does not exist)
// case 2: specified path is created before calling ExtractToDirectory
string dir2 = @"C:\temp\some2\path2";
Directory.CreateDirectory(dir2);
ZipFile.ExtractToDirectory(@"C:\temp\some.zip", dir2); // works, but according to the docs should not (because dir does exist)
### Expected behavior
The docs should match the behavior of the code and don't make contradictory statements.
### Actual behavior
Calling `ExtractToDirectory` works in all cases. It doesn't matter if the specified directory exists or doesn't, but the docs say otherwise.
### Regression?
_No response_
### Known Workarounds
_No response_
### Configuration
_No response_
### Other information
_No response_
<table>
<tr>
<th align="left">Author:</th>
<td>cn-byn</td>
</tr>
<tr>
<th align="left">Assignees:</th>
<td>-</td>
</tr>
<tr>
<th align="left">Labels:</th>
<td>
`area-System.IO`
</td>
</tr>
<tr>
<th align="left">Milestone:</th>
<td>-</td>
</tr>
</table>
</details> |
Tagging subscribers to this area: @dotnet/area-system-io-compression Issue DetailsDescriptionThe documentation comments of the
and
Additionally,
and
Looking through the source code, most of the statements don't seem to be true and it seems totally fine to provide a directory path that either exists or doesn't. That's because those methods call // in ZipFileExtensions.ZipArchiveEntry.Extract.cs:
// Note that this will give us a good DirectoryInfo even if destinationDirectoryName exists:
DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName); Reproduction Steps// case 1: specified path does not exist
string dir1 = @"C:\temp\some1\path1";
ZipFile.ExtractToDirectory(@"C:\temp\some.zip", dir1); // works, but according to the docs should not (because parent dir does not exist)
// case 2: specified path is created before calling ExtractToDirectory
string dir2 = @"C:\temp\some2\path2";
Directory.CreateDirectory(dir2);
ZipFile.ExtractToDirectory(@"C:\temp\some.zip", dir2); // works, but according to the docs should not (because dir does exist) Expected behaviorThe docs should match the behavior of the code and don't make contradictory statements. Actual behaviorCalling Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Thanks @cn-byn - do you want to offer a PR? |
I can work on this. |
If a file that is being extracted already exists then it throws IOException stating that file already exists. Although exception message can be improved but claim from docs can be considered true. Should we change it? PS: I have synchronised the descriptions of cc: @danmoseley |
Resolved in #100330 |
Description
The documentation comments of the
ZipFile.ExtractToDirectory
methods say:and
Additionally,
ZipFileExtensions.ExtractToDirectory
contradictorily claims:and
Looking through the source code, most of the statements don't seem to be true and it seems totally fine to provide a directory path that either exists or doesn't.
That's because those methods call
ZipFileExtensions.ExtractRelativeToDirectory
and there the directory is created (with a comment):Reproduction Steps
Expected behavior
The docs should match the behavior of the code and don't make contradictory statements.
Actual behavior
Calling
ExtractToDirectory
works in all cases. It doesn't matter if the specified directory exists or doesn't, but the docs say otherwise.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: