mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2025-01-28 22:04:43 -08:00
patchutils.py: fix crash when a patch deletes a file
This commit is contained in:
parent
ec47c04ab3
commit
06c1bde586
@ -387,8 +387,11 @@ def read_patch(filename, fp=None):
|
||||
|
||||
def apply_patch(original, patchfile, reverse=False, fuzz=2):
|
||||
"""Apply a patch with optional fuzz - uses the commandline 'patch' utility."""
|
||||
if original is None:
|
||||
raise PatchApplyError("Failed to apply patch - file was deleted (exitcode %d)." % exitcode)
|
||||
|
||||
result = tempfile.NamedTemporaryFile(prefix="apply_patch", mode='w+', delete=False)
|
||||
|
||||
result = tempfile.NamedTemporaryFile(mode='w+', delete=False)
|
||||
try:
|
||||
# We open the file again to avoid race-conditions with multithreaded reads
|
||||
with open(original.name) as fp:
|
||||
@ -404,6 +407,9 @@ def apply_patch(original, patchfile, reverse=False, fuzz=2):
|
||||
if exitcode != 0:
|
||||
raise PatchApplyError("Failed to apply patch (exitcode %d)." % exitcode)
|
||||
|
||||
if not os.path.exists(result.name):
|
||||
return None
|
||||
|
||||
# Hack - we can't keep the file open while patching ('patch' might rename/replace
|
||||
# the file), so create a new _TemporaryFileWrapper object for the existing path.
|
||||
return tempfile._TemporaryFileWrapper(file=open(result.name, 'r+'), \
|
||||
|
Loading…
x
Reference in New Issue
Block a user