def _directory_path_for_file(path):
    """
    Given a path, return the directory its metadata file is in and the filename
    of the file inside it.
    """
    if path.real_file and path.is_dir():
        # If this is a directory on disk, put the metadata for the directory itself inside
        # the directory instead of in the parent directory.  Don't do this for ZIPs (which
        # are "directories" but we don't write files into them).
        directory_path = path
    else:
        # Put data about the file in the containing directory.
        directory_path = path.filesystem_parent

    filename = path.relative_to(directory_path)
    return directory_path, filename