commit:     f6212ee060d6a2962ac27cf57ffd721d14b64215
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 21 14:13:21 2021 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Wed Feb 24 15:32:07 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f6212ee0

desktop.eclass: Avoid file collisions in make_desktop_entry()

Closes: https://bugs.gentoo.org/771708
Reported-by: Sergey Torokhov <torokhov-s-a <AT> yandex.ru>
Suggested-by: Ionen Wolkens <sudinave <AT> gmail.com>
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

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

diff --git a/eclass/desktop.eclass b/eclass/desktop.eclass
index 7d5c0f0f9a2..82e764e2a1a 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:+;}

Reply via email to