def create_or_update(avatar, name, container_path, fullpath, metadata=None,
                     on_behalf=None):
    """Create or update a container."""
    log.msg("Container create/update: %s" % fullpath)

    parent_container = get_parent(fullpath)
    uid, vals = vcdm.env['ds'].find_by_path(fullpath, object_type='container',
                                            fields=['children',
                                                    'parent_container',
                                                    'owner'])
    vals['uid'] = uid
    # XXX: duplication of checks with blob (vcdm). Refactor.
    if uid is not None and parent_container != vals['parent_container']:
        log.err("Inconsistency! path: %s, parent_container in db: %s" % (fullpath, vals['parent_container']))
        return (FORBIDDEN, vals)

    # assert we can write to the defined path
    if not check_path(container_path):
        log.err("Writing to a container is not allowed. Container path: %s" %
                '/'.join(container_path))
        return (FORBIDDEN, vals)

    # authorize call, take parent permissions
    _, cvals = vcdm.env['ds'].find_by_path(parent_container,
                                           object_type='container',
                                           fields=['metadata'])
    acl = cvals['metadata'].get('cdmi_acl', {})
    if not authorize(avatar, parent_container, "write_container", acl):
        return (UNAUTHORIZED, vals)

    # add default acls
    if avatar is None:
            avatar = 'Anonymous'
    container_acl = metadata.get('cdmi_acl')
    if container_acl is None:
        metadata['cdmi_acl'] = acl  # append parent ACLs for a new folder
    metadata['cdmi_acl'].update({avatar: 'rwd'})  # and creator's ACLs

    # if uid is None, it shall create a new entry, update otherwise
    if uid is None:
        uid = vcdm.env['ds'].write({
                        'object': 'container',
                        'metadata': metadata,
                        'owner': avatar,
                        'fullpath': fullpath,
                        'name': name,
                        'parent_container': parent_container,
                        'children': {},
                        'ctime': str(time.time()),
                        'mtime': str(time.time())},
                        uid)
        vals['uid'] = uid
        # update the parent container as well, unless it's a top-level container
        if fullpath != '/':
            _append_child(parent_container, uid, name + "/")
        log.msg(type='accounting', avatar=avatar if not on_behalf else on_behalf,
                amount=1, acc_type='container_create')
        return (CREATED, vals)
    else:
        # update container
        # forbid rewrites of containers by other users
        if vals.get('owner') is not None and vals.get('owner') != avatar:
            return (UNAUTHORIZED, vals)
        uid = vcdm.env['ds'].write({
                        'metadata': metadata,
                        'mtime': str(time.time())},
                        uid)
        log.msg(type='accounting', avatar=avatar if not on_behalf else on_behalf,
                amount=1, acc_type='container_update')
        return (NO_CONTENT, vals)
dataset/ETHPy150Open livenson/vcdm/src/vcdm/container.py/create_or_update/original