Skip to contentSkip to conversation

build.py: fix os.getcwd() exception

PATCH In review Juro Bystricky 2 participants 2 messages Sep 26, 2016 – Sep 27, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build.py: fix os.getcwd() exception

When trying to obtain the current directory from a directory that does not exist anymore, an exception is raised. This patch handles such exception.

[YOCTO #10331]

---
 bitbake/lib/bb/build.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
bitbake/lib/bb/build.py +7 -2
index 2ed0441..249f7d6 100644
@@ -261,9 +261,14 @@ def exec_func(func, d, dirs = None, pythonexception=False):
         else:
             exec_func_shell(func, d, runfile, cwd=adir)
 
-    if oldcwd and os.getcwd() != oldcwd:
+    try:
+        curcwd = os.getcwd()
+    except:
+        curcwd = None
+
+    if oldcwd and curcwd != oldcwd:
         try:
-            bb.warn("Task %s changed cwd to %s" % (func, os.getcwd()))
+            bb.warn("Task %s changed cwd to %s" % (func, curcwd))
             os.chdir(oldcwd)
         except:
             pass
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Juro Bystricky

When trying to obtain the current directory from a directory that does not exist anymore, an exception is raised. This patch handles such exception.

This should have gone to bitbake-devel, I've cc'd there and queued in master-next for testing.

Cheers,

Richard

Quoted 30 lines

[YOCTO #10331]

---
 bitbake/lib/bb/build.py | 9 +++++++--

 1 file changed, 7 insertions(+), 2 deletions(-)
bitbake/lib/bb/build.py +0 -0
index 2ed0441..249f7d6 100644
@@ -261,9 +261,14 @@ def exec_func(func, d, dirs = None,

pythonexception=False):
         else:
             exec_func_shell(func, d, runfile, cwd=adir)
-    if oldcwd and os.getcwd() != oldcwd:
+    try:
+        curcwd = os.getcwd()
+    except:
+        curcwd = None
+
+    if oldcwd and curcwd != oldcwd:
         try:
-            bb.warn("Task %s changed cwd to %s" % (func, os.getcwd()))
+            bb.warn("Task %s changed cwd to %s" % (func, curcwd)) os.chdir(oldcwd)
         except:
             pass