restructure #3

Merged
wyj merged 82 commits from dev into main 2026-01-18 20:12:27 -05:00
3 changed files with 217 additions and 0 deletions
Showing only changes of commit 3fc6b2e81a - Show all commits

View File

@@ -0,0 +1,53 @@
pkgname=xdg-utils
pkgver=1.2.1
pkgdesc="Portland utils for cross-platform/cross-toolkit/cross-desktop interoperability"
homepage="https://www.freedesktop.org/wiki/Software/xdg-utils/"
license=("MIT")
depends=(
dev-util/desktop-file-utils
x11-misc/shared-mime-info
dbus
)
_patches=("xdg-utils-1.2.1-qtpaths.patch"
"xdg-utils-1.2.1-xdg-mime-default.patch"
)
_patch_sums=("9a7942e38ecad2bdbebdd558557647648c21bfec132f72bb7c3f2ae737345fb1e552e7fa6a118223da663ae4e3ac4d9776ec3f46f031ad2499141ab83db5c99a"
"0e57d5cf9fa9969738c1d836c4c3b644cc6e1e80cd7486ec5ca0fdb2c86f0f5e3988c4790faf1838ad09946803347a96c0fd47373c5971c691c20d4913845ad1"
)
sources=("${pkgname}-${pkgver}.tar.bz2"
"${_patches[@]}"
)
urls=("https://gitlab.freedesktop.org/xdg/xdg-utils/-/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.bz2"
"${_patches[@]}"
)
sha512sums=("d5436449fec2f4db952239ee910bfda203955c8df8cb92379f182dc36f9c82b6ceb092ccbebfd02ed00eb7ef5f6895ef745baca67906ae7490e425db27b1dbfc"
"${_patch_sums[@]}"
)
src_prepare() {
tar -xf ${distdir}/${sources[0]} --strip-components=1
for _patch in ${_patches[@]}; do
patch -p1 -i ${filedir}/${_patch}
done
autoreconf -fiv
}
src_build() {
./configure --prefix=/usr --mandir=/usr/share/man
make -C scripts scripts-clean
make
}
src_install() {
make DESTDIR="$pkgdir" install
echo XDG_DATA_DIRS=\"/usr/local/share\" > 30xdg-data-local
echo 'COLON_SEPARATED="XDG_DATA_DIRS XDG_CONFIG_DIRS"' >> 30xdg-data-local
install -vDm644 30xdg-data-local -t "${pkgdir}"/etc/env.d
echo XDG_DATA_DIRS=\"/usr/share\" > 90xdg-data-base
echo XDG_CONFIG_DIRS=\"/etc/xdg\" >> 90xdg-data-base
install -vDm644 90xdg-data-base -t "${pkgdir}"/etc/env.d
}
# vim:ft=sh syn=sh et sw=2:

View File

@@ -0,0 +1,21 @@
Workaround for https://bugs.gentoo.org/934941.
Pending questions:
* Should qt6paths instead be in /usr/bin in Gentoo?
* Why do we have a qtpaths6 as well as a qt6paths?
--- a/scripts/xdg-mime.in
+++ b/scripts/xdg-mime.in
@@ -166,8 +166,11 @@ make_default_kde()
# text/plain=gnome-gedit.desktop;gnu-emacs.desktop;
vendor="$1"
mimetype="$2"
- if [ "${KDE_SESSION_VERSION:-0}" -gt 4 ] ; then
- default_dir="$(qtpaths --writable-path ConfigLocation)"
+ if [ "${KDE_SESSION_VERSION:-0}" -gt 5 ] ; then
+ default_dir="$($(pkg-config --variable=bindir Qt6Core)/qtpaths6 --writable-path ConfigLocation)"
+ default_file="$default_dir/mimeapps.list"
+ elif [ x"$KDE_SESSION_VERSION" = x"5" ] ; then
+ default_dir="$(qtpaths5 --writable-path ConfigLocation)"
default_file="$default_dir/mimeapps.list"
elif [ x"$KDE_SESSION_VERSION" = x"4" ]; then
default_dir="$(kde4-config --path xdgdata-apps 2> /dev/null | cut -d ':' -f 1)"

View File

@@ -0,0 +1,143 @@
https://gitlab.freedesktop.org/xdg/xdg-utils/-/issues/252
https://gitlab.freedesktop.org/xdg/xdg-utils/-/commit/f113a8b997dcb9527b9694d31bddcfa05096aecf
From f113a8b997dcb9527b9694d31bddcfa05096aecf Mon Sep 17 00:00:00 2001
From: Slatian <baschdel@disroot.org>
Date: Tue, 21 May 2024 04:08:23 +0000
Subject: [PATCH] Make the desktop_file_to_binary function less likely to fall
over and do something unexpected.
* Uses a shell implementation ( !24) of `which` in the `desktop_file_to_binary` to avoid tripping over unexpected output from `command -v`
* In addition it also makes the parsing a bit more standards compliant than it previously was.
* Adds a developer script to easier test internal functions in the xdg-utils-common.in file
Fixes: #252
---
scripts/test-common-function | 13 ++++++++
scripts/xdg-utils-common.in | 64 +++++++++++++++++++++++++++++++-----
2 files changed, 68 insertions(+), 9 deletions(-)
create mode 100755 scripts/test-common-function
diff --git a/scripts/test-common-function b/scripts/test-common-function
new file mode 100755
index 0000000..c8af98d
--- /dev/null
+++ b/scripts/test-common-function
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# This script is for testing internal functions of the xdg-utils-common.in file
+#
+# Example ./test-common-function xdg_which echo
+
+XDG_UTILS_DEBUG_LEVEL="${XDG_UTILS_DEBUG_LEVEL:-99}"
+
+. ./xdg-utils-common.in
+
+"$@"
+
+exit $?
diff --git a/scripts/xdg-utils-common.in b/scripts/xdg-utils-common.in
index f0a1aac..adab368 100644
--- a/scripts/xdg-utils-common.in
+++ b/scripts/xdg-utils-common.in
@@ -51,19 +51,24 @@ binary_to_desktop_file()
}
#-------------------------------------------------------------
-# map a .desktop file to a binary
+# map a .desktop file name to its Exec binary
+# Returns the realpath resolved path to the binary or noting.
+
+# desktop_file_to_binary <desktop-file-name>
desktop_file_to_binary()
{
+ DEBUG 1 "desktop_file_to_binary '$1'"
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
desktop="$(basename "$1")"
IFS=:
for dir in $search; do
+ DEBUG 2 "Searching in '$dir/{applications,applnk}'"
unset IFS
- [ "$dir" ] && [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
+ [ -n "$dir" ] && [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
# Check if desktop file contains -
if [ "${desktop#*-}" != "$desktop" ]; then
- vendor=${desktop%-*}
- app=${desktop#*-}
+ vendor="${desktop%-*}"
+ app="${desktop#*-}"
if [ -r "$dir/applications/$vendor/$app" ]; then
file_path="$dir/applications/$vendor/$app"
elif [ -r "$dir/applnk/$vendor/$app" ]; then
@@ -72,18 +77,31 @@ desktop_file_to_binary()
fi
if test -z "$file_path" ; then
for indir in "$dir"/applications/ "$dir"/applications/*/ "$dir"/applnk/ "$dir"/applnk/*/; do
+ DEBUG 4 "Does file exist? '$indir/$desktop'"
file="$indir/$desktop"
if [ -r "$file" ]; then
- file_path=$file
+ file_path="$file"
break
fi
done
fi
if [ -r "$file_path" ]; then
- # Remove any arguments (%F, %f, %U, %u, etc.).
- command="$(grep -E "^Exec(\[[^]=]*])?=" "$file_path" | cut -d= -f 2- | first_word)"
- command="$(command -v "$command")"
- xdg_realpath "$command"
+ DEBUG 2 "Checking desktop file '$file_path'"
+ # Get the command name from the correct Exec
+ # Note: Ignoring quoting and escape sequences here, see #253
+ binary="$(awk -F '=' '
+ /^\[/{ in_entry=0 }
+ $0 == "[Desktop Entry]"{ in_entry=1 }
+ in_entry && /^Exec\s*=/ {
+ sub(/^\s+/,"",$2);
+ match($2,/^[^ ]+/);
+ print substr($2,RSTART,RLENGTH)
+ }' \
+ < "$file_path" )"
+ DEBUG 2 "Found command: $binary"
+ binary="$(xdg_which "$binary")"
+ DEBUG 2 "Resolved to command to file: '$binary'"
+ [ -z "$binary" ] || xdg_realpath "$binary"
return
fi
done
@@ -461,3 +479,31 @@ xdg_realpath()
;;
esac
}
+
+#----------------------------------------------------------------------------
+# The `which` command but as a shell implementation.
+# Returns either the path of the resolved binary or nothing
+# because command -v does not always return the path of a command
+# (builtins, aliases, functions, etc.)
+
+# xdg_which <command>
+xdg_which()
+{
+ if [ -z "$1" ] ; then
+ return 1
+ elif [ -x "$1" ] ; then
+ printf "%s\n" "$1"
+ else
+ # this should be faster than the real thing because of shell builtins
+ old_ifs="$IFS"
+ IFS=:
+ for p in $PATH ; do
+ IFS="$old_ifs"
+ if [ -x "$p/$1" ] ; then
+ printf "%s\n" "$p/$1"
+ return
+ fi
+ done
+ return 1
+ fi
+}
--
GitLab