summaryrefslogtreecommitdiff
blob: d1285caf4c0173e5f2c5be86791bcb5873d7957b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# check for missing calls to xdg-utils regen functions

xdg_desktop_database_check() {
	type -P update-desktop-database &>/dev/null || return

	local d f all_files=() missing
	for d in usr/share/applications; do
		[[ -d ${d} ]] || continue

		local files=() find_args=()
		# if the cache does not exist at all, we complain for any file
		# otherwise, we look for files newer than the cache
		[[ -f ${d}/mimeinfo.cache ]] &&
			find_args+=( -newercm "${d}"/mimeinfo.cache ) || missing=1

		# look for any .desktop files that are newer than the cache
		# and that have any mime types defined
		while read -r -d $'\0' f; do
			files+=( "${f}" )
		done < <(find "${d}" -name '*.desktop' "${find_args[@]}" \
			-exec grep -lZi '^MimeType=' {} +)

		# if any files were found, update the db to avoid repeating
		# the warning for subsequent packages
		if [[ ${files[@]} ]]; then
			all_files+=("${files[@]}")
			addwrite "${d}"
			update-desktop-database "${d}"
		fi
	done

	# The eqatag call is prohibitively expensive if the cache is
	# missing and there are a large number of files.
	if [[ -z ${missing} && ${all_files[@]} ]]; then
		eqawarn "QA Notice: .desktop files with MimeType= were found installed"
		eqawarn "but desktop mimeinfo cache has not been updated:"
		eqatag -v xdg-utils.desktop "${all_files[@]/#//}"
		eqawarn "Please make sure to call xdg_desktop_database_update()"
		eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
	fi
}

xdg_mimeinfo_database_check() {
	type -P update-mime-database &>/dev/null || return

	local d f all_files=() missing
	for d in usr/share/mime; do
		[[ -d ${d} ]] || continue

		local files=() find_args=()
		# if the cache does not exist at all, we complain for any file
		# otherwise, we look for files newer than the cache
		[[ -f ${d}/mime.cache ]] &&
			find_args+=( -newercm "${d}"/mime.cache ) || missing=1

		while read -r -d $'\0' f; do
			files+=( "${f}" )
		done < <(find "${d}" -name '*.xml' "${find_args[@]}" -print0)

		# if any files were found, update the db to avoid repeating
		# the warning for subsequent packages
		if [[ ${files[@]} ]]; then
			all_files+=("${files[@]}")
			addwrite "${d}"
			update-mime-database "${d}"
		fi
	done

	# The eqatag call is prohibitively expensive if the cache is
	# missing and there are a large number of files.
	if [[ -z ${missing} && ${all_files[@]} ]]; then
		eqawarn "QA Notice: mime-info files were found installed but mime-info"
		eqawarn "cache has not been updated:"
		eqatag -v xdg-utils.mime-info "${all_files[@]/#//}"
		eqawarn "Please make sure to call xdg_mimeinfo_database_update()"
		eqawarn "in pkg_postinst() and pkg_postrm() phases of appropriate pkgs."
	fi
}

xdg_utils_postinst_check() {
	cd "${EROOT}" || die
	xdg_desktop_database_check
	xdg_mimeinfo_database_check
}

xdg_utils_postinst_check
: # guarantee successful exit

# vim:ft=sh