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

FileShare change to ReadWrite #109104

Closed
wants to merge 1 commit into from
Closed

FileShare change to ReadWrite #109104

wants to merge 1 commit into from

Conversation

BaY1251
Copy link

@BaY1251 BaY1251 commented Oct 22, 2024

No description provided.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 22, 2024
@BaY1251 BaY1251 changed the title Update ZipFileExtensions.ZipArchive.Create.cs FileShare change to ReadWrite Oct 22, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

@huoyaoyuan
Copy link
Member

This is a behavioral change that doesn't look correct. Zip expects consistency within a file. The same file shouldn't be written simultaneously.

@BaY1251
Copy link
Author

BaY1251 commented Oct 22, 2024

@huoyaoyuan Some files, such as log files, are opened by writing throughout the entire lifecycle of the program.The folder containing these files can never be packaged.

@pentp
Copy link
Contributor

pentp commented Oct 22, 2024

You can just create ZipArchiveEntry directly yourself. Using CreateEntryFromFile isn't appropriate in such situations.

@BaY1251
Copy link
Author

BaY1251 commented Oct 24, 2024

@pentp I did solve it as you said, but most of the time people don't want to encounter exceptions when using ZipArchive and spend a lot of time looking for temporary solutions

@huoyaoyuan
Copy link
Member

but most of the time people don't want to encounter exceptions when using ZipArchive

This is not true. Most of the time people are expecting the methods to be reliable. Reading files that are written by other process requires extra causion and collaboration with the writer. This is not reliable by default.

@BaY1251
Copy link
Author

BaY1251 commented Oct 25, 2024

Using compression software such as WinRar, built-in compression in Windows 11, etc., can all be used normally.
Unless debugged under these specific conditions, it will never be found that ZipFile performs differently from mainstream compression software

@ericstj
Copy link
Member

ericstj commented Dec 17, 2024

Agree with what is said by @huoyaoyuan. Opening a file with write sharing could cause us to write a torn file when we previously would have failed to write at all. Consider in the middle of the call CopyTo a writer writes to both the beginning (missed) and end (observed) of file -- we'd have read a torn version of the file.

You should be able to use other API to perform this action if you can somehow guarantee that other writers to the file will never actually write it, but we should not take this change.

If you'd like to further discuss you can do so in an issue.

@ericstj ericstj closed this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO.Compression community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants