Make sure the given attributes exist on the file/directory

    name
        The path to the file/directory

    attributes
        The attributes that should exist on the file/directory, this is accepted as
        an array, with key and value split with an equals sign, if you want to specify
        a hex value then add 0x to the beginning of the value.

def exists(name, attributes):
    '''
    Make sure the given attributes exist on the file/directory

    name
        The path to the file/directory

    attributes
        The attributes that should exist on the file/directory, this is accepted as
        an array, with key and value split with an equals sign, if you want to specify
        a hex value then add 0x to the beginning of the value.

    '''
    ret = {'name': name,
           'result': True,
           'comment': '',
           'changes': {}}

    if not os.path.exists(name):
        ret['result'] = False
        ret['comment'] = "File or directory doesn't exist"
        return ret

    current_attrs = __salt__['xattr.list'](name)
    current_ids = current_attrs.keys()

    for attr in attributes:
        attr_id, attr_val = attr.split("=")
        attr_hex = attr_val.startswith("0x")

        if attr_hex:
            # Remove spaces and new lines so we can match these
            current_attrs[attr_id] = __salt__['xattr.read'](name, attr_id, hex=True).replace(" ", "").replace("\n", "")
            attr_val = attr_val[2:].replace(" ", "")

        if attr_id not in current_attrs:
            value_matches = False
        else:
            value_matches = ((current_attrs[attr_id] == attr_val) or
                             (attr_hex and current_attrs[attr_id] == attr_val))

        if attr_id in current_ids and value_matches:
            continue
        else:
            ret['changes'][attr_id] = attr_val
            __salt__['xattr.write'](name, attr_id, attr_val, attr_hex)

    if not ret['changes']:
        ret['comment'] = 'All values existed correctly.'

    return ret