lib/oe/patch: ensure os.chdir restoring always happens

If we chdir(), do the chdir back to the original directory in a finally
block so they always run.

(From OE-Core rev: 1680d1766445b21e35c6b874c4767b385862017f)

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit cdc40292818683b6df1c814498c7589450a163fa)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
This commit is contained in:
Ross Burton
2023-11-21 14:06:17 +00:00
committed by Steve Sakoman
parent dc33087410
commit 911935d7bd

View File

@@ -772,8 +772,9 @@ class NOOPResolver(Resolver):
self.patchset.Push() self.patchset.Push()
except Exception: except Exception:
import sys import sys
os.chdir(olddir)
raise raise
finally:
os.chdir(olddir)
# Patch resolver which relies on the user doing all the work involved in the # Patch resolver which relies on the user doing all the work involved in the
# resolution, with the exception of refreshing the remote copy of the patch # resolution, with the exception of refreshing the remote copy of the patch
@@ -833,9 +834,9 @@ class UserResolver(Resolver):
# User did not fix the problem. Abort. # User did not fix the problem. Abort.
raise PatchError("Patch application failed, and user did not fix and refresh the patch.") raise PatchError("Patch application failed, and user did not fix and refresh the patch.")
except Exception: except Exception:
os.chdir(olddir)
raise raise
os.chdir(olddir) finally:
os.chdir(olddir)
def patch_path(url, fetch, workdir, expand=True): def patch_path(url, fetch, workdir, expand=True):