-
Notifications
You must be signed in to change notification settings - Fork 0
/
pk-backend-remove.c
156 lines (130 loc) · 4.82 KB
/
pk-backend-remove.c
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 Andreas Obergrusberger <tradiaz@yahoo.de>
* Copyright (C) 2008-2010 Valeriy Lyasotskiy <onestep@ukr.net>
* Copyright (C) 2010-2011 Jonathan Conder <jonno.conder@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <alpm.h>
#include <pk-backend.h>
#include "pk-backend-alpm.h"
#include "pk-backend-error.h"
#include "pk-backend-remove.h"
#include "pk-backend-transaction.h"
static gboolean
pk_backend_transaction_remove_targets (PkBackend *self, GError **error, gchar **package_ids)
{
gchar **packages;
guint i;
guint lpackages;
const gchar *package;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (alpm != NULL, FALSE);
g_return_val_if_fail (localdb != NULL, FALSE);
lpackages = g_strv_length(package_ids);
for (i=0; i<lpackages; i++) {
package=package_ids[i];
gchar **package = pk_package_id_split (package);
gchar *name = package[PK_PACKAGE_ID_NAME];
alpm_pkg_t *pkg = alpm_db_get_pkg (localdb, name);
if (pkg == NULL || alpm_remove_pkg (alpm, pkg) < 0) {
alpm_errno_t errno = alpm_errno (alpm);
g_set_error (error, ALPM_ERROR, errno, "%s: %s", name,
alpm_strerror (errno));
g_strfreev (package);
return FALSE;
}
g_strfreev (package);
}
return TRUE;
}
static gboolean
pk_backend_transaction_remove_simulate (PkBackend *self, GError **error)
{
const alpm_list_t *i;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (alpm != NULL, FALSE);
if (!pk_backend_transaction_simulate (self, error)) {
return FALSE;
}
for (i = alpm_trans_get_remove (alpm); i != NULL; i = i->next) {
const gchar *name = alpm_pkg_get_name (i->data);
if (alpm_list_find_str (holdpkgs, name)) {
g_set_error (error, ALPM_ERROR, ALPM_ERR_PKG_HELD,
"%s: %s", name,
"could not remove HoldPkg");
return FALSE;
}
}
return TRUE;
}
static gboolean
pk_backend_simulate_remove_packages_thread (PkBackend *self, PkBackendJob *job, gchar **package_ids)
{
alpm_transflag_t flags = ALPM_TRANS_FLAG_CASCADE;
GError *error = NULL;
g_return_val_if_fail (self != NULL, FALSE);
/* remove unneeded packages that were required by those to be removed */
//if (pk_backend_get_bool (self, "autoremove")) {
// flags |= ALPM_TRANS_FLAG_RECURSE;
//}
if (pk_backend_transaction_initialize (self, flags, &error) &&
pk_backend_transaction_remove_targets (self, &error, package_ids) &&
pk_backend_transaction_remove_simulate (self, &error)) {
pk_backend_transaction_packages (self);
}
return pk_backend_transaction_finish (self, error);
}
static gboolean
pk_backend_remove_packages_thread (PkBackend *self, PkBackendJob *job, gchar **package_ids)
{
alpm_transflag_t flags = 0;
GError *error = NULL;
g_return_val_if_fail (self != NULL, FALSE);
/* remove packages that depend on those to be removed */
//if (pk_backend_get_bool (self, "allow_deps")) {
// flags |= ALPM_TRANS_FLAG_CASCADE;
//}
/* remove unneeded packages that were required by those to be removed */
//if (pk_backend_get_bool (self, "autoremove")) {
// flags |= ALPM_TRANS_FLAG_RECURSE;
//}
if (pk_backend_transaction_initialize (self, flags, &error) &&
pk_backend_transaction_remove_targets (self, &error, package_ids) &&
pk_backend_transaction_remove_simulate (self, &error)) {
pk_backend_transaction_commit (self, &error);
}
return pk_backend_transaction_finish (self, error);
}
void
pk_backend_simulate_remove_packages (PkBackend *self, PkBackendJob *job, PkBitfield transaction_flags, gchar **package_ids, gboolean allow_deps, gboolean autoremove)
{
g_return_if_fail (self != NULL);
g_return_if_fail (package_ids != NULL);
pk_backend_run (self, job, PK_STATUS_ENUM_SETUP,
pk_backend_simulate_remove_packages_thread);
}
void
pk_backend_remove_packages (PkBackend *self, PkBackendJob *job, PkBitfield transaction_flags,gchar **package_ids,
gboolean allow_deps, gboolean autoremove)
{
g_return_if_fail (self != NULL);
g_return_if_fail (package_ids != NULL);
pk_backend_run (self, job, PK_STATUS_ENUM_SETUP,
pk_backend_remove_packages_thread);
}