.. versionchanged: 2016.3.0

    List the files that belong to a package.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.file_dict nginx
        salt '*' pkg.file_dict nginx varnish

def file_dict(*packages, **kwargs):
    '''
    .. versionchanged: 2016.3.0

    List the files that belong to a package.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.file_dict nginx
        salt '*' pkg.file_dict nginx varnish
    '''
    errors = []
    files = {}

    for package in packages:
        cmd = ['pkg_info', '-qL', package]
        ret = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
        files[package] = []
        for line in ret['stderr'].splitlines():
            errors.append(line)

        for line in ret['stdout'].splitlines():
            if line.startswith('/'):
                files[package].append(line)
            else:
                continue  # unexpected string

    ret = {'errors': errors, 'files': files}
    for field in list(ret):
        if not ret[field] or ret[field] == '':
            del ret[field]
    return ret