Avoid zip extract racing condition by using read+write instead extract#5707
Merged
sigmavirus24 merged 1 commit intopsf:masterfrom Jul 7, 2021
gaborbernat:5223
Merged
Avoid zip extract racing condition by using read+write instead extract#5707sigmavirus24 merged 1 commit intopsf:masterfrom gaborbernat:5223
sigmavirus24 merged 1 commit intopsf:masterfrom
gaborbernat:5223
Conversation
Extract also creates the folder hierarchy, however we do not need that, the file itself being extracted to a temporary folder is good enough. Instead we read the content of the zip and then write it. The write is not locked but it's OK to update the same file multiple times given the update operation will not alter the content of the file. By not creating the folder hierarchy (default via extract) we no longer can run into the problem of two parallel extracts both trying to create the folder hierarchy without exists ok flag, and one must fail. Resolves #5223. Signed-off-by: Bernát Gábor <[email protected]>
gaborbernat
commented
Dec 24, 2020
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def atomic_open(filename): |
Contributor
Author
There was a problem hiding this comment.
Just to handle a further race condition that can happen between opening and writing the file.
Contributor
Author
|
@sigmavirus24 @nateprewitt would you be able to accept this, so we can fix a long outstanding pip issue? Thanks! |
Contributor
Author
|
@sigmavirus24 @nateprewitt do you have any plan to have a look at this? |
sigmavirus24
approved these changes
Jul 7, 2021
Merged
jonfung-scale
pushed a commit
to jonfung-scale/jonfung-requests
that referenced
this pull request
Jul 14, 2021
psf#5707) Extract also creates the folder hierarchy, however we do not need that, the file itself being extracted to a temporary folder is good enough. Instead we read the content of the zip and then write it. The write is not locked but it's OK to update the same file multiple times given the update operation will not alter the content of the file. By not creating the folder hierarchy (default via extract) we no longer can run into the problem of two parallel extracts both trying to create the folder hierarchy without exists ok flag, and one must fail. Resolves psf#5223. Signed-off-by: Bernát Gábor <[email protected]>
jonfung-scale
pushed a commit
to jonfung-scale/jonfung-requests
that referenced
this pull request
Jul 14, 2021
psf#5707) Extract also creates the folder hierarchy, however we do not need that, the file itself being extracted to a temporary folder is good enough. Instead we read the content of the zip and then write it. The write is not locked but it's OK to update the same file multiple times given the update operation will not alter the content of the file. By not creating the folder hierarchy (default via extract) we no longer can run into the problem of two parallel extracts both trying to create the folder hierarchy without exists ok flag, and one must fail. Resolves psf#5223. Signed-off-by: Bernát Gábor <[email protected]>
jonfung-scale
pushed a commit
to jonfung-scale/jonfung-requests
that referenced
this pull request
Jul 15, 2021
psf#5707) Extract also creates the folder hierarchy, however we do not need that, the file itself being extracted to a temporary folder is good enough. Instead we read the content of the zip and then write it. The write is not locked but it's OK to update the same file multiple times given the update operation will not alter the content of the file. By not creating the folder hierarchy (default via extract) we no longer can run into the problem of two parallel extracts both trying to create the folder hierarchy without exists ok flag, and one must fail. Resolves psf#5223. Signed-off-by: Bernát Gábor <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract also creates the folder hierarchy, however we do not need that,
the file itself being extracted to a temporary folder is good enough.
Instead we read the content of the zip and then write it. The write is
not locked but it's OK to update the same file multiple times given the
update operation will not alter the content of the file. By not creating
the folder hierarchy (default via extract) we no longer can run into the
problem of two parallel extracts both trying to create the folder
hierarchy without exists ok flag, and one must fail.
Resolves #5223.
Signed-off-by: Bernát Gábor [email protected]