def makedirs(self, path, **kw):
        """Make directory specified by 'path' with given permissions, as
                well as all missing parent directories.  Permissions are
                specified by the keyword arguments 'mode', 'uid', and 'gid'.

                The difference between this and os.makedirs() is that the
                permissions specify only those of the leaf directory.  Missing
                parent directories inherit the permissions of the deepest
                existing directory.  The leaf directory will also inherit any
                permissions not explicitly set."""

        # generate the components of the path.  The first
        # element will be empty since all absolute paths
        # always start with a root specifier.
        pathlist = portable.split_path(path)

        # Fill in the first path with the root of the filesystem
        # (this ends up being something like C:\ on windows systems,
        # and "/" on unix.
        pathlist[0] = portable.get_root(path)

        g = enumerate(pathlist)
        for i, e in g:
            # os.path.isdir() follows links, which isn't
            # desirable here.
            p = os.path.join(*pathlist[:i + 1])
            try:
                fs = os.lstat(p)
            except OSError, e:
                if e.errno == errno.ENOENT:
                    break
                raise

            if not stat.S_ISDIR(fs.st_mode):
                if p == path:
                    # Allow caller to handle target by
                    # letting the operation continue,
                    # and whatever error is encountered
                    # being raised to the caller.
                    break

                err_txt = _("Unable to create %(path)s; a "
                    "parent directory %(p)s has been replaced "
                    "with a file or link.  Please restore the "
                    "parent directory and try again.") % \
                    locals()
                raise apx.ActionExecutionError(self,
                                               details=err_txt,
                                               error=e,
                                               fmri=kw.get("fmri", None))
        def makedirs(self, path, **kw):
                """Make directory specified by 'path' with given permissions, as
                well as all missing parent directories.  Permissions are
                specified by the keyword arguments 'mode', 'uid', and 'gid'.

                The difference between this and os.makedirs() is that the
                permissions specify only those of the leaf directory.  Missing
                parent directories inherit the permissions of the deepest
                existing directory.  The leaf directory will also inherit any
                permissions not explicitly set."""

                # generate the components of the path.  The first
                # element will be empty since all absolute paths
                # always start with a root specifier.
                pathlist = portable.split_path(path)

                # Fill in the first path with the root of the filesystem
                # (this ends up being something like C:\ on windows systems,
                # and "/" on unix.
                pathlist[0] = portable.get_root(path)

                g = enumerate(pathlist)
                for i, e in g:
                        # os.path.isdir() follows links, which isn't
                        # desirable here.
                        p = os.path.join(*pathlist[:i + 1])
                        try:
                                fs = os.lstat(p)
                        except OSError, e:
                                if e.errno == errno.ENOENT:
                                        break
                                raise

                        if not stat.S_ISDIR(fs.st_mode):
                                if p == path:
                                        # Allow caller to handle target by
                                        # letting the operation continue,
                                        # and whatever error is encountered
                                        # being raised to the caller.
                                        break

                                err_txt = _("Unable to create %(path)s; a "
                                    "parent directory %(p)s has been replaced "
                                    "with a file or link.  Please restore the "
                                    "parent directory and try again.") % \
                                    locals()
                                raise apx.ActionExecutionError(self,
                                    details=err_txt, error=e,
                                    fmri=kw.get("fmri", None))
Example #3
0
        def makedirs(path, **kw):
                """Make directory specified by 'path' with given permissions, as
                well as all missing parent directories.  Permissions are
                specified by the keyword arguments 'mode', 'uid', and 'gid'.

                The difference between this and os.makedirs() is that the
                permissions specify only those of the leaf directory.  Missing
                parent directories inherit the permissions of the deepest
                existing directory.  The leaf directory will also inherit any
                permissions not explicitly set."""

                # generate the components of the path.  The first
                # element will be empty since all absolute paths
                # always start with a root specifier.
                pathlist = portable.split_path(path)

                # Fill in the first path with the root of the filesystem
                # (this ends up being something like C:\ on windows systems,
                # and "/" on unix.
                pathlist[0] = portable.get_root(path)

                g = enumerate(pathlist)
                for i, e in g:
                        if not os.path.isdir(os.path.join(*pathlist[:i + 1])):
                                break
                else:
                        # XXX Because the filelist codepath may create
                        # directories with incorrect permissions (see
                        # pkgtarfile.py), we need to correct those permissions
                        # here.  Note that this solution relies on all
                        # intermediate directories being explicitly created by
                        # the packaging system; otherwise intermediate
                        # directories will not get their permissions corrected.
                        stat = os.stat(path)
                        mode = kw.get("mode", stat.st_mode)
                        uid = kw.get("uid", stat.st_uid)
                        gid = kw.get("gid", stat.st_gid)
                        try:
                                if mode != stat.st_mode:
                                        os.chmod(path, mode)
                                if uid != stat.st_uid or gid != stat.st_gid:
                                        portable.chown(path, uid, gid)
                        except  OSError, e:
                                if e.errno != errno.EPERM and \
                                    e.errno != errno.ENOSYS:
                                        raise
                        return
Example #4
0
    def makedirs(path, **kw):
        """Make directory specified by 'path' with given permissions, as
                well as all missing parent directories.  Permissions are
                specified by the keyword arguments 'mode', 'uid', and 'gid'.

                The difference between this and os.makedirs() is that the
                permissions specify only those of the leaf directory.  Missing
                parent directories inherit the permissions of the deepest
                existing directory.  The leaf directory will also inherit any
                permissions not explicitly set."""

        # generate the components of the path.  The first
        # element will be empty since all absolute paths
        # always start with a root specifier.
        pathlist = portable.split_path(path)

        # Fill in the first path with the root of the filesystem
        # (this ends up being something like C:\ on windows systems,
        # and "/" on unix.
        pathlist[0] = portable.get_root(path)

        g = enumerate(pathlist)
        for i, e in g:
            if not os.path.isdir(os.path.join(*pathlist[:i + 1])):
                break
        else:
            # XXX Because the filelist codepath may create
            # directories with incorrect permissions (see
            # pkgtarfile.py), we need to correct those permissions
            # here.  Note that this solution relies on all
            # intermediate directories being explicitly created by
            # the packaging system; otherwise intermediate
            # directories will not get their permissions corrected.
            stat = os.stat(path)
            mode = kw.get("mode", stat.st_mode)
            uid = kw.get("uid", stat.st_uid)
            gid = kw.get("gid", stat.st_gid)
            try:
                if mode != stat.st_mode:
                    os.chmod(path, mode)
                if uid != stat.st_uid or gid != stat.st_gid:
                    portable.chown(path, uid, gid)
            except OSError, e:
                if e.errno != errno.EPERM and \
                    e.errno != errno.ENOSYS:
                    raise
            return