public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] desktop.eclass: Avoid file collisions in make_desktop_entry()
@ 2021-02-21 14:23 Ulrich Müller
  2021-02-21 15:08 ` [gentoo-dev] [PATCH v2] " Ulrich Müller
  0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Müller @ 2021-02-21 14:23 UTC (permalink / raw
  To: gentoo-dev
  Cc: base-system, Ulrich Müller, Sergey Torokhov, Ionen Wolkens

Closes: https://bugs.gentoo.org/771708
Reported-by: Sergey Torokhov <torokhov-s-a@yandex.ru>
Suggested-by: Ionen Wolkens <sudinave@gmail.com>
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
---
 eclass/desktop.eclass | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/eclass/desktop.eclass b/eclass/desktop.eclass
index 7d5c0f0f9a26..72d315448266 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
@@ -163,7 +163,14 @@ make_desktop_entry() {
 		local desktop_name="${PN}-${slot}"
 	fi
 	local desktop="${exec%%[[:space:]]*}"
-	desktop="${T}/${desktop##*/}-${desktop_name}.desktop"
+	desktop="${desktop##*/}-${desktop_name}"
+
+	# Prevent collisions if a file with the same name already exists #771708
+	local desktop_base="${desktop}" count=0
+	while [[ -e ${ED}/usr/share/applications/${desktop}.desktop ]]; do
+		desktop="${desktop_base}-$((++count))"
+	done
+	desktop="${T}/${desktop}.desktop"
 
 	# Don't append another ";" when a valid category value is provided.
 	type=${type%;}${type:+;}
-- 
2.30.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-dev] [PATCH v2] desktop.eclass: Avoid file collisions in make_desktop_entry()
  2021-02-21 14:23 [gentoo-dev] [PATCH] desktop.eclass: Avoid file collisions in make_desktop_entry() Ulrich Müller
@ 2021-02-21 15:08 ` Ulrich Müller
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Müller @ 2021-02-21 15:08 UTC (permalink / raw
  To: gentoo-dev
  Cc: base-system, Ulrich Müller, Sergey Torokhov, Ionen Wolkens

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-21 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-21 14:23 [gentoo-dev] [PATCH] desktop.eclass: Avoid file collisions in make_desktop_entry() Ulrich Müller
2021-02-21 15:08 ` [gentoo-dev] [PATCH v2] " Ulrich Müller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox