summaryrefslogtreecommitdiffstats
path: root/src/remove.sh
blob: a2d06a681f2aa001eb024b6e39631e24668dc55b (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
90
# pro-archman
# src/remove.sh
# Functions for removing packges
#
# Copyright (C) 2013  Patrick McDermott
#
# This file is part of the ProteanOS Archive Manager.
#
# The ProteanOS Archive Manager is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# The ProteanOS Archive Manager is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the ProteanOS Archive Manager.  If not, see
# <http://www.gnu.org/licenses/>.

remove_source_from_suite()
{
	local chan="${1}"
	local dist="${2}"
	local source="${3}"
	shift 3
	local arch=
	local plat=

	info "$(get_msg 'removing_from_suite')" \
		"${source}" "${chan}" "${dist}"

	while read -r arch plat; do
		remove_packages_from_suite_archplat \
			"${chan}" "${dist}" "${arch}" "${plat}" "${source}"
	done <<-EOF
		$(db_get_archplats "${chan}" "${dist}" "${source}")
		EOF

	db_del_srcver "${chan}" "${dist}" "${source}"

	return 0
}

remove_packages_from_suite_archplat()
{
	local chan="${1}"
	local dist="${2}"
	local arch="${3}"
	local plat="${4}"
	local source="${5}"
	shift 5
	local binver=
	local refs=
	local size=
	local sect=
	local pkg=
	local file=

	info_v "$(get_msg 'removing_from_suite_archplat')" \
		"${source}" "${chan}" "${dist}" "${arch}" "${plat}"

	binver="$(db_get_binver "${chan}" "${dist}" "${arch}" "${plat}" \
		"${source}")"
	if [ "x${binver}" = 'x' ]; then
		return 0
	fi
	db_del_binver "${chan}" "${dist}" "${arch}" "${plat}" "${source}"
	refs=$(db_dec_references "${arch}" "${plat}" "${source}" "${binver}")

	while read -r size sect pkg; do
		feed_remove_package "${chan}" "${dist}" "${arch}" "${plat}" \
			"${sect}" "${pkg}"
		if [ ${refs} -eq 0 ]; then
			file="pool/$(hash_name "${source}")/${source}"
			file="${file}/${pkg}_${binver}_${arch}_${plat}.opk"
			mark_pool_garbage "${file}"
		fi
	done <<-EOF
		$(db_get_packages "${arch}" "${plat}" "${source}" "${binver}")
		EOF

	if [ ${refs} -eq 0 ]; then
		db_del_packages "${arch}" "${plat}" "${source}" "${binver}"
	fi

	return 0
}