[PATCH] Be more resilient against $PATH errors

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 2 08:46:24 UTC 2019


Close #3781.
---
 source-builder/sb/check.py | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/source-builder/sb/check.py b/source-builder/sb/check.py
index 9e4e953..be808ea 100644
--- a/source-builder/sb/check.py
+++ b/source-builder/sb/check.py
@@ -104,20 +104,24 @@ def path_check(opts, silent = False):
     if 'PATH' in os.environ:
         paths = os.environ['PATH'].split(os.pathsep)
         for p in paths:
-            if len(p.strip()) == 0:
+            try:
+                if len(p.strip()) == 0:
+                    if not silent:
+                        log.notice('error: environment PATH contains an empty path')
+                    return False
+                elif not options.host_windows and (p.strip() == '.' or p.strip() == '..'):
+                    if not silent:
+                        log.notice('error: environment PATH invalid path: %s' % (p))
+                    return False
+                elif not path.exists(p):
+                    if not silent and opts.warn_all():
+                        log.notice('warning: environment PATH not found: %s' % (p))
+                elif not path.isdir(p):
+                    if not silent and opts.warn_all():
+                        log.notice('warning: environment PATH not a directory: %s' % (p))
+            except Exception as e:
                 if not silent:
-                    log.notice('error: environment PATH contains an empty path')
-                return False
-            elif not options.host_windows and (p.strip() == '.' or p.strip() == '..'):
-                if not silent:
-                    log.notice('error: environment PATH invalid path: %s' % (p))
-                return False
-            elif not path.exists(p):
-                if not silent and opts.warn_all():
-                    log.notice('warning: environment PATH not found: %s' % (p))
-            elif not path.isdir(p):
-                if not silent and opts.warn_all():
-                    log.notice('warning: environment PATH not a directory: %s' % (p))
+                    log.notice('warning: environment PATH suspicious path: %s' % (e))
     return True
 
 
-- 
2.16.4



More information about the devel mailing list