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

Richard Purdie richard.purdie at linuxfoundation.org
Thu May 10 11:19:19 UTC 2012


On Wed, 2012-05-09 at 17:22 -0700, Joshua Lock wrote:
> 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

I'm afraid there are a few holes here. mkdirhier can create parents and
your chmod doesn't change these. I also agree with the comments, I think
this needs to remain unchanged behaviour wise, respecting the umask and
only set a mode if its specified.

Cheers,

Richard






More information about the Openembedded-core mailing list