commit:     6f742be11d6bbfb7e15632a5eacc585329459708
Author:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Mon Dec  8 18:39:29 2025 +0000
Commit:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Fri Dec 12 22:20:41 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6f742be1

desktop.eclass: make_desktop_entry: die on duplicate file unless --force

Pre- --eapi9 behavior masked such collisions by suffixing the resulting
desktop file name by an auto-incrementing number. This led to undetected
desktop file duplications if e.g. upstream began to ship their own, when
ebuilds had been compensating via make_desktop_entry() previously.

With --desktopid, we now have necessary direct control over the resulting
file name, so the auto-increment file suffix was dropped.

Without this change, doins would happily overwrite an existing file.

Bug: https://bugs.gentoo.org/771708
Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>

 eclass/desktop.eclass | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/eclass/desktop.eclass b/eclass/desktop.eclass
index 299d3d6f739f..5dcc695bfcdc 100644
--- a/eclass/desktop.eclass
+++ b/eclass/desktop.eclass
@@ -50,6 +50,7 @@ _DESKTOP_IDS=()
 #             defined in code (including reverse qualified domain if set);
 #             defaults to <command>
 # comment:    Comment (menu entry tooltip), defaults to DESCRIPTION
+# force:      Force-write resulting desktop file (overwrite existing)
 # @CODE
 #
 # Example usage:
@@ -82,7 +83,7 @@ make_desktop_entry() {
        [[ -z ${1} ]] && die "make_desktop_entry: You must specify at least a 
command"
 
        if [[ ${eapi9} ]]; then
-               local args cats cmd comment desktopid entries icon name
+               local args cats cmd comment desktopid entries force icon name
                while [[ $# -gt 0 ]] ; do
                        case "${1}" in
                        -a|--args)
@@ -95,6 +96,8 @@ make_desktop_entry() {
                                desktopid="${2}";    shift 2 ;;
                        -e|--entry)
                                entries+=( "${2}" ); shift 2 ;;
+                       -f|--force)
+                               force=1;             shift 1 ;;
                        -i|--icon)
                                icon="${2}";         shift 2 ;;
                        -n|--name)
@@ -259,6 +262,9 @@ make_desktop_entry() {
                        _DESKTOP_IDS+=( "${desktopid}" )
                fi
                local desktop="${T}/${desktopid}.desktop"
+               if [[ ! ${force} && -e 
${ED}/usr/share/applications/${desktopid}.desktop ]]; then
+                       die "make_desktop_entry: desktopid \"${desktopid}\" 
already exists, must be unique"
+               fi
        else
                local desktop_exec="${cmd%%[[:space:]]*}"
                desktop_exec="${desktop_exec##*/}"

Reply via email to