[PATCH 1 of 3] util.makedirs: propagate chmod exceptions

Adrian Buehlmann adrian at cadifra.com
Mon Aug 22 02:10:10 CDT 2011


On 2011-08-22 01:07, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1313966142 -7200
> # Branch stable
> # Node ID b2881a5ceecc79052c48103eeb04d3d4d02ee3ee
> # Parent  7f504202cb5c62e37d07441180ebc866b8ea02b8
> util.makedirs: propagate chmod exceptions
> 
> The existing exception handling was intended to handle mkdir errors. Strange
> chmod exceptions could thus have strange consequences - or be swallowed.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -760,16 +760,15 @@
>      parent = os.path.abspath(os.path.dirname(name))
>      try:
>          os.mkdir(name)
> -        if mode is not None:
> -            os.chmod(name, mode)
> -        return
>      except OSError, err:
>          if err.errno == errno.EEXIST:
>              return
>          if not name or parent == name or err.errno != errno.ENOENT:
>              raise
> -    makedirs(parent, mode)
> -    makedirs(name, mode)
> +        makedirs(parent, mode)
> +        makedirs(name, mode)
> +    if mode is not None:
> +        os.chmod(name, mode)
>  
>  def readfile(path):
>      fp = open(path, 'rb')

+1
Looks good to me


More information about the Mercurial-devel mailing list