Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/eselect-fontconfig:master commit in: /
Date: Sun, 03 Apr 2022 00:28:21
Message-Id: 1648945674.f57b6d44c764b18c1bf9c8ceb0574aa7103f760d.sam@gentoo
1 commit: f57b6d44c764b18c1bf9c8ceb0574aa7103f760d
2 Author: David Michael <fedora.dm0 <AT> gmail <DOT> com>
3 AuthorDate: Thu Jul 1 19:42:33 2021 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sun Apr 3 00:27:54 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/eselect-fontconfig.git/commit/?id=f57b6d44
7
8 Use relative symlinks
9
10 This eselect module writes its links with absolute paths which include ${EROOT}
11 prefixes. This results in broken links when using the file system
12 mounted at ${ROOT} natively.
13
14 The main fix is using the --relative argument to ln, which has been available
15 for about a decade in coreutils.
16
17 (If that's not portable enough, I'd recommend dropping the
18 ES_FONTCONFIG_DIRS variable so paths are predictable.
19 It doesn't appear to be documented anywhere anyway.)
20
21 The file also updates syntax a bit to simplify it and adhere to modern
22 Gentoo style conventions. I dropped its behavior of overriding system
23 files if a file with the same name is in the current working directory,
24 since it seems dangerous. That behavior could still be used by prefixing
25 files with the "./" path (but I'd prefer to drop support for specifying
26 directories as well so it only accepts the file names/indices as they are
27 printed).
28
29 [sam: reformatted/gitified git message from Bugzilla comment]
30
31 Closes: https://bugs.gentoo.org/799758
32 Signed-off-by: David Michael <fedora.dm0 <AT> gmail.com>
33 Signed-off-by: Sam James <sam <AT> gentoo.org>
34
35 fontconfig.eselect | 106 ++++++++++++++++++++---------------------------------
36 1 file changed, 40 insertions(+), 66 deletions(-)
37
38 diff --git a/fontconfig.eselect b/fontconfig.eselect
39 index cb3e25a..d7f90f0 100644
40 --- a/fontconfig.eselect
41 +++ b/fontconfig.eselect
42 @@ -1,36 +1,26 @@
43 # -*-eselect-*- vim: ft=eselect
44 -# Copyright 1999-2009 Gentoo Foundation
45 +# Copyright 1999-2022 Gentoo Authors
46 # Distributed under the terms of the GNU General Public License v2
47 -# $Id: fontconfig.eselect 728 2009-11-14 21:08:28Z dirtyepic $
48
49 -DESCRIPTION="Manage fontconfig /etc/fonts/conf.d/ symlinks"
50 +DESCRIPTION="Manage fontconfig /etc/fonts/conf.d symlinks"
51 AUTHOR="cardoe@g.o"
52 MAINTAINER="fonts@g.o"
53 -SVN_DATE='$Date: 2009-11-14 15:08:28 -0600 (Sat, 14 Nov 2009) $'
54 -VERSION=$(svn_date_to_version "${SVN_DATE}")
55 +VERSION=20220403
56
57 find_targets() {
58 - local targets bc x i=0
59 - bcdirs[i]="${EROOT}/etc/fonts/conf.avail/*.conf"
60 + local bc bcdirs=()
61
62 - if [[ -n "${ES_FONTCONFIG_DIRS}" ]] ; then
63 - for x in ${ES_FONTCONFIG_DIRS} ; do
64 - bcdirs[$((++i))]="${x}/*"
65 - done
66 - fi
67 -
68 - for bc in ${bcdirs[@]} ; do
69 - [[ -e ${bc} && ${bc} != *~ ]] && targets="${targets}\n$(basename ${bc})"
70 + for bc in /etc/fonts/conf.avail ${ES_FONTCONFIG_DIRS}; do
71 + bcdirs+=("${EROOT}${bc}/*.conf")
72 done
73
74 - echo -ne ${targets} | sort -u
75 + for bc in ${bcdirs[@]}; do
76 + [[ -e ${bc} ]] && echo "${bc##*/}"
77 + done | sort -u
78 }
79
80 is_enabled() {
81 - bcdir="${EROOT}/etc/fonts/conf.d"
82 -
83 - [[ -e ${bcdir}/${1} ]] || return 1
84 - return 0
85 + [[ -e ${EROOT}/etc/fonts/conf.d/${1} ]]
86 }
87
88 ### list action ###
89 @@ -40,18 +30,15 @@ describe_list() {
90 }
91
92 do_list() {
93 - local n
94 - targets=( $(find_targets) )
95 + local n targets=($(find_targets))
96 write_list_start \
97 "Available fontconfig .conf files ($(highlight '*') is enabled):"
98
99 for (( n = 0; n < ${#targets[@]}; ++n )); do
100 - is_enabled ${targets[n]} \
101 - && targets[n]=$(highlight_marker "${targets[n]}")
102 + is_enabled "${targets[n]}" &&
103 + targets[n]=$(highlight_marker "${targets[n]}")
104 done
105 write_numbered_list -m "(none found)" "${targets[@]}"
106 -
107 - return 0
108 }
109
110 ### enable action ###
111 @@ -69,30 +56,30 @@ describe_enable_options() {
112 }
113
114 do_enable() {
115 - local bc bcdir="${EROOT}/etc/fonts/conf.d"
116 + local bc bcdir="${EROOT}/etc/fonts/conf.d" x
117
118 [[ -z ${1} ]] && die -q "You didn't specify any .conf files to enable"
119
120 # create directory if necessary
121 - if [[ ! -d ${bcdir} && -w $(dirname ${bcdir}) ]] ; then
122 + if [[ ! -d ${bcdir} && -w ${bcdir%/*} ]] ; then
123 mkdir ${bcdir} || die -q "Failed to create ${bcdir}"
124 elif [[ ! -d ${bcdir} ]] ; then
125 die -q "You don't have permission to create ${bcdir}"
126 fi
127
128 # make sure we have proper permissions
129 - [[ -w ${bcdir} ]] || \
130 + [[ -w ${bcdir} ]] ||
131 die -q "You don't have permission to write to ${bcdir}"
132
133 - targets=( $(find_targets) )
134 + local targets=($(find_targets))
135
136 - for bc in $@ ; do
137 + for bc; do
138 local file target=${bc}
139
140 - is_number "${target}" && \
141 - target=${targets[$(( ${target} - 1 ))]}
142 + is_number "${target}" &&
143 + target=${targets[${target} - 1]}
144
145 - [[ -z "${target}" ]] && \
146 + [[ -z ${target} ]] &&
147 die -q "Target \"${bc}\" doesn't appear to be valid!"
148
149 bc=${target}
150 @@ -101,52 +88,39 @@ do_enable() {
151 [[ ${bc} == --* ]] && continue
152
153 # what form is the argument in?
154 - case "${bc}" in
155 + case ${bc} in
156 # absolute path
157 /*)
158 - file="${EROOT}/${bc}"
159 + file="${EROOT}${bc}"
160 ;;
161 # relative path
162 */*)
163 - file="${EROOT}/${PWD}/${bc}"
164 + file="${EROOT}${PWD}/${bc}"
165 ;;
166 # no path
167 *)
168 - # CWD
169 - if [[ -f ${bc} ]] ; then
170 - file="${EROOT}/${PWD}/${bc}"
171 - # assume /etc/fonts/conf.avail
172 - elif [[ -f ${EROOT}/etc/fonts/conf.avail/${bc} ]]
173 - then
174 - file="${EROOT}/etc/fonts/conf.avail/${bc}"
175 - else
176 - if [[ -n "${ES_FONTCONFIG_DIRS}" ]] ; then
177 - for x in ${ES_FONTCONFIG_DIRS} ; do
178 - [[ -f ${x}/${bc} ]] && file="${x}/${bc}"
179 - done
180 - fi
181 -
182 - [[ -e ${file} ]] || \
183 - file="${EROOT}/etc/fonts/conf.avail/${bc}"
184 - fi
185 + [[ -n ${ES_FONTCONFIG_DIRS} ]] &&
186 + for x in ${ES_FONTCONFIG_DIRS}; do
187 + [[ -f ${EROOT}${x}/${bc} ]] && file="${EROOT}${x}/${bc}" && break
188 + done || file="${EROOT}/etc/fonts/conf.avail/${bc}"
189 ;;
190 esac
191
192 # does it exist?
193 - if [[ ! -e ${file} ]] ; then
194 + if [[ ! -e ${file} ]]; then
195 write_error_msg "${file} doesn't exist"
196 continue
197 fi
198
199 # already installed?
200 - if [[ -e ${bcdir}/$(basename ${bc}) ]] ; then
201 - write_error_msg "$(basename ${bc}) is already installed"
202 + if [[ -e ${bcdir}/${bc##*/} ]]; then
203 + write_error_msg "${bc##*/} is already installed"
204 continue
205 fi
206
207 # finally, create the symlink
208 - ln -s "${file}" "${bcdir}" || \
209 - die -q "Failed to create symlink from '${file}' to '${bcdir}'"
210 + ln -rs "${file}" "${bcdir}" ||
211 + die -q "Failed to create symlink from \"${file}\" to \"${bcdir}\""
212 done
213 }
214
215 @@ -170,15 +144,15 @@ do_disable() {
216
217 [[ -z ${1} ]] && die -q "You didn't specify any .conf files to disable"
218
219 - targets=( $(find_targets) )
220 + local targets=($(find_targets))
221
222 - for bc in $@ ; do
223 + for bc; do
224 local file target=${bc}
225
226 - is_number "${target}" && \
227 - target=${targets[$(( ${target} - 1 ))]}
228 + is_number "${target}" &&
229 + target=${targets[${target} - 1]}
230
231 - [[ -z "${target}" ]] && \
232 + [[ -z ${target} ]] &&
233 die -q "Target \"${bc}\" doesn't appear to be valid!"
234
235 bc=${target}
236 @@ -188,13 +162,13 @@ do_disable() {
237 [[ ${bc} == --* ]] && continue
238
239 # is in installed?
240 - if [[ ! -e ${file} ]] ; then
241 + if [[ ! -e ${file} ]]; then
242 write_error_msg "${bc} is not installed"
243 continue
244 fi
245
246 # remove it if we have permissions
247 - if [[ -w $(dirname ${file}) ]] ; then
248 + if [[ -w ${file%/*} ]]; then
249 rm "${file}" || die -q "Failed to remove ${file}"
250 else
251 die -q "You don't have permission to remove ${file}"