[OE-core] [RFC PATCH 1/3] lib/bb/utils.py: add optional mode parameter to bb.utils.mkdirhier()

Joshua Lock josh at linux.intel.com
Thu May 10 00:22:46 UTC 2012


The optional parameter should be an octal file mode representing the
desired permissions of the created directory. If mode isn;t specified
use 0777. This is the default of os.makedirs() yet is not often what
the created directory ends up with due to umask affecting the call.

The use of chmod() in this patch ensures that whatever octal is
passed are the permissions the directory will have after creation.
This is a behaviour change...

Signed-off-by: Joshua Lock <josh at linux.intel.com>
---
 bitbake/lib/bb/utils.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 7a73419..33206fe 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -531,13 +531,16 @@ def prune_suffix(var, suffixes, d):
             return var.replace(suffix, "")
     return var
 
-def mkdirhier(directory):
+def mkdirhier(directory, mode=0777):
     """Create a directory like 'mkdir -p', but does not complain if
     directory already exists like os.makedirs
     """
 
     try:
-        os.makedirs(directory)
+        os.makedirs(directory, mode)
+        # We can't rely on makedirs having set the mode correctly as it is
+        # affected by umask
+        os.chmod(directory, mode)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise e
-- 
1.7.7.6





More information about the Openembedded-core mailing list