Closes: https://bugs.gentoo.org/771708
Reported-by: Sergey Torokhov <torokhov-...@yandex.ru>
Suggested-by: Ionen Wolkens <sudin...@gmail.com>
Signed-off-by: Ulrich Müller <u...@gentoo.org>
---
v2: Insert counter after executable name, not after package name.
    See https://bugs.gentoo.org/771708#c9 for rationale.

 eclass/desktop.eclass | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/eclass/desktop.eclass b/eclass/desktop.eclass
index 7d5c0f0f9a26..82e764e2a1a4 100644
--- a/eclass/desktop.eclass
+++ b/eclass/desktop.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2020 Gentoo Authors
+# Copyright 1999-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: desktop.eclass
@@ -162,8 +162,15 @@ make_desktop_entry() {
        else
                local desktop_name="${PN}-${slot}"
        fi
-       local desktop="${exec%%[[:space:]]*}"
-       desktop="${T}/${desktop##*/}-${desktop_name}.desktop"
+       local desktop_exec="${exec%%[[:space:]]*}"
+       desktop_exec="${desktop_exec##*/}"
+
+       # Prevent collisions if a file with the same name already exists #771708
+       local desktop="${desktop_exec}-${desktop_name}" count=0
+       while [[ -e ${ED}/usr/share/applications/${desktop}.desktop ]]; do
+               desktop="${desktop_exec}-$((++count))-${desktop_name}"
+       done
+       desktop="${T}/${desktop}.desktop"
 
        # Don't append another ";" when a valid category value is provided.
        type=${type%;}${type:+;}
-- 
2.30.1


Reply via email to