Function ensure_tree in fileutils.py have permission problems

Bug #1655562 reported by Hao Li
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.utils
Confirmed
Undecided
Unassigned

Bug Description

Follow is the master branch code:
def ensure_tree(path, mode=_DEFAULT_MODE):
    """Create a directory (and any ancestor directories required)
    :param path: Directory to create
    :param mode: Directory creation permissions
    """
    try:
        os.makedirs(path, mode)
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            if not os.path.isdir(path):
                raise
        else:
            raise

This code: os.makedirs(path, mode), CAN'T set the dir permision right.
when openstack ironic project make dirs for tftp, It wants to make the new dir 0777, but it only 755 permissions or 750 permissions.

Same problem:
http://stackoverflow.com/questions/5231901/permission-problems-when-creating-a-dir-with-os-makedirs-python

I think we should change the code to:
def ensure_tree(path, mode=_DEFAULT_MODE):
    """Create a directory (and any ancestor directories required)
    :param path: Directory to create
    :param mode: Directory creation permissions
    """
    try:
        original_umask = os.umask(0)
        os.makedirs(path, mode)
        os.umask(original_umask)
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            if not os.path.isdir(path):
                raise
        else:
            raise

Revision history for this message
ChangBo Guo(gcb) (glongwave) wrote :

thanks for reporting this issue .Not sure os.umask will affect the python process only or the operating system. If the whole operating system. it seems not a good solution.

Maybe we need another function to handle the case without affecting other consumers

Revision history for this message
ChangBo Guo(gcb) (glongwave) wrote :

Do you have any bug link for ironic ?

Changed in oslo.utils:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.