Skip to contentSkip to conversation

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

PATCH New [email protected] 1 participant 1 message Nov 21, 2023

lore
Share & tools
lore
#0 lore raw

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

From: Ross Burton <[email protected]>

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

---
 meta/lib/oe/patch.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
meta/lib/oe/patch.py +4 -3
index ff9afc9df9f..9b480b2b285 100644
@@ -772,8 +772,9 @@ class NOOPResolver(Resolver):
             self.patchset.Push()
         except Exception:
             import sys
-            os.chdir(olddir)
             raise
+        finally:
+            os.chdir(olddir)
 
 # 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
@@ -833,9 +834,9 @@ class UserResolver(Resolver):
                             # User did not fix the problem.  Abort.
                             raise PatchError("Patch application failed, and user did not fix and refresh the patch.")
         except Exception:
-            os.chdir(olddir)
             raise
-        os.chdir(olddir)
+        finally:
+            os.chdir(olddir)
 
 
 def patch_path(url, fetch, workdir, expand=True):
Signature · 1 line
2.34.1