This is an attempt to fix bug #208047 [1] and bug #444568 [2]

Current fdo-mime eclass is often not used when it should be. I suppose
this is partly because one has to think too much about whether it is
needed or not and what to do with the functions.

The proposed solution is to not have to worry about it and just inherit
it when you have any kind of XDG specifications support and let the
exported phases do their job in a similar fashion to the gnome
eclasses.

For now, this covers .desktop and shared mime-info files and creating
base directory for packages that rely on it one way or another.

This helps solve problems like bug #545128 [3] and others that have
been covered by previous work resulting in gnome2_environment_reset
function and similar in other eclasses (cmake-utils, gstreamer, kde4
-base, mono, mono-env, qt4-*).


[1] [Bug 208047] fdo-mime.eclass should depend on desktop-file-utils
    https://bugs.gentoo.org/show_bug.cgi?id=208047

[2] [Bug 444568] [Future EAPI] Export XDG_* variables in ebuild 
    environment
    https://bugs.gentoo.org/show_bug.cgi?id=444568

[3] [Bug 545128] media-sound/pulseaudio-6.0 XDG_RUNTIME_DIR
    (/run/user/1000) is not owned by us (uid 0)
    https://bugs.gentoo.org/show_bug.cgi?id=545128

-- 
Gilles Dartiguelongue <e...@gentoo.org>
Gentoo
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: xdg.eclass
# @MAINTAINER:
# freedesktop-b...@gentoo.org
# @AUTHOR:
# Original author: Gilles Dartiguelongue <e...@gentoo.org>
# @BLURB: Provides phases for XDG compliant packages.
# @DESCRIPTION:
# Utility eclass to update the desktop and shared mime info as laid
# out in the freedesktop specs & implementations

inherit xdg-utils

case "${EAPI:-0}" in
        4|5)
                EXPORT_FUNCTIONS src_prepare pkg_preinst pkg_postinst pkg_postrm
                ;;
        *) die "EAPI=${EAPI} is not supported" ;;
esac

DEPEND="
        dev-util/desktop-file-utils
        x11-misc/shared-mime-info
"

# @FUNCTION: xdg_src_prepare
# @DESCRIPTION:
# Prepare sources to work with XDG standards.
xdg_src_prepare() {
        # Prepare XDG base directories
        export XDG_DATA_HOME="${T}/.local/share"
        export XDG_CONFIG_HOME="${T}/.config"
        export XDG_CACHE_HOME="${T}/.cache"
        export XDG_RUNTIME_DIR="${T}/run"
        mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
                "${XDG_RUNTIME_DIR}"
        # This directory needs to be owned by the user, and chmod 0700
        # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
        chmod 0700 "${XDG_RUNTIME_DIR}"
}

# @FUNCTION: xdg_pkg_preinst
# @DESCRIPTION:
# Finds .desktop and mime info files for later handling in pkg_postinst
xdg_pkg_preinst() {
        xdg_desktopfiles_savelist
        xdg_mimeinfo_savelist
}

# @FUNCTION: xdg_pkg_postinst
# @DESCRIPTION:
# Handle desktop and mime info database updates.
xdg_pkg_postinst() {
        xdg_desktop_database_update
        xdg_mimeinfo_database_update
}

# @FUNCTION: xdg_pkg_postrm
# @DESCRIPTION:
# Handle desktop and mime info database updates.
xdg_pkg_postrm() {
        xdg_desktop_database_update
        xdg_mimeinfo_database_update
}

# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: xdg-utils.eclass
# @MAINTAINER:
# gn...@gentoo.org
# @AUTHOR:
# Original author: Gilles Dartiguelongue <e...@gentoo.org>
# @BLURB: Auxiliary functions commonly used by XDG compliant packages.
# @DESCRIPTION:
# This eclass provides a set of auxiliary functions needed by most XDG
# compliant packages.
# It provides XDG stack related functions such as:
#  * XDG .desktop files cache management
#  * XDG mime information database management

case "${EAPI:-0}" in
        4|5) ;;
        *) die "EAPI=${EAPI} is not supported" ;;
esac

# @ECLASS-VARIABLE: DESKTOP_DATABASE_UPDATE_BIN
# @INTERNAL
# @DESCRIPTION:
# Path to update-desktop-database
: ${DESKTOP_DATABASE_UPDATE_BIN:="/usr/bin/update-desktop-database"}

# @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
# @INTERNAL
# @DESCRIPTION:
# Directory where .desktop files database is stored
: ${DESKTOP_DATABASE_DIR="/usr/share/applications"}

# @ECLASS-VARIABLE: MIMEINFO_DATABASE_UPDATE_BIN
# @INTERNAL
# @DESCRIPTION:
# Path to update-desktop-database
: ${MIMEINFO_DATABASE_UPDATE_BIN:="/usr/bin/update-mime-database"}

# @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
# @INTERNAL
# @DESCRIPTION:
# Directory where .desktop files database is stored
: ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}

# @FUNCTION: xdg_desktopfiles_savelist
# @DESCRIPTION:
# Find the .desktop files about to be installed and save their location
# in the XDG_ECLASS_DESKTOPFILES environment variable.
# This function should be called from pkg_preinst.
xdg_desktopfiles_savelist() {
        pushd "${D}" &> /dev/null
        export XDG_ECLASS_DESKTOPFILES=$(find 'usr/share/applications' -type f 
2> /dev/null)
        popd &> /dev/null
}

# @FUNCTION: fdo-xdg_desktop_database_update
# @DESCRIPTION:
# Updates the .desktop files database.
# Generates a list of mimetypes linked to applications that can handle them
xdg_desktop_database_update() {
        local updater="${EROOT}${DESKTOP_DATABASE_UPDATE_BIN}"

        if [[ ! -x "${updater}" ]] ; then
                debug-print "${updater} is not executable"
                return
        fi

        if [[ -z "${XDG_ECLASS_DESKTOPFILES}" ]]; then
                debug-print "No .desktop files to add to database"
                return
        fi

        ebegin "Updating .desktop files database ..."
        "${updater}" -q "${EROOT}${DESKTOP_DATABASE_DIR}"
        eend $?
}

# @FUNCTION: xdg_mimeinfo_savelist
# @DESCRIPTION:
# Find the mime information files about to be installed and save their location
# in the XDG_ECLASS_MIMEINFOFILES environment variable.
# This function should be called from pkg_preinst.
xdg_mimeinfo_savelist() {
        pushd "${D}" &> /dev/null
        export XDG_ECLASS_MIMEINFOFILES=$(find 'usr/share/mime' -type f 2> 
/dev/null)
        popd &> /dev/null
}

# @FUNCTION: xdg_mimeinfo_database_update
# @DESCRIPTION:
# Update the mime database.
# Creates a general list of mime types from several sources
xdg_mimeinfo_database_update() {
        local updater="${EROOT}${MIMEINFO_DATABASE_UPDATE_BIN}"

        if [[ ! -x "${updater}" ]] ; then
                debug-print "${updater} is not executable"
                return
        fi

        if [[ -z "${XDG_ECLASS_MIMEINFOFILES}" ]]; then
                debug-print "No mime info files to add to database"
                return
        fi

        ebegin "Updating shared mime info database ..."
        "${updater}" "${EROOT}${MIMEINFO_DATABASE_DIR}"
        eend $?
}

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to