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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
#if defined(__APPLE__) || defined(__OpenBSD__)
#include <sys/syslimits.h>
#endif
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun__)
#include <sys/stat.h>
#endif
#include "config.h"
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <limits.h>
#include <zlib.h>
#include <libintl.h>
#include "list.h"
#include "trans.h"
#include "util.h"
#include "error.h"
#include "versioncmp.h"
#include "md5.h"
#include "sha1.h"
#include "log.h"
#include "backup.h"
#include "package.h"
#include "db.h"
#include "cache.h"
#include "deps.h"
#include "provide.h"
#include "remove.h"
#include "handle.h"
#include "alpm.h"
int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
{
pmpkg_t *info;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
if(_alpm_pkg_isin(name, trans->packages)) {
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}
if((info = _alpm_db_scan(db, name, INFRQ_ALL)) == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not find %s in database"), name);
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
}
if((trans == handle->trans) && _alpm_list_is_strin(info->name, handle->holdpkg)) {
int resp = 0;
QUESTION(trans, PM_TRANS_CONV_REMOVE_HOLDPKG, info, NULL, NULL, &resp);
if(!resp) {
RET_ERR(PM_ERR_PKG_HOLD, -1);
}
}
_alpm_log(PM_LOG_FLOW2, _("adding %s in the targets list"), info->name);
trans->packages = _alpm_list_add(trans->packages, info);
return(0);
}
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, pmlist_t **data)
{
pmlist_t *lp;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) {
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, _("looking for unsatisfied dependencies"));
lp = _alpm_checkdeps(trans, db, trans->type, trans->packages);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
while(lp) {
pmlist_t *i;
for(i = lp; i; i = i->next) {
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
pmpkg_t *info = _alpm_db_scan(db, miss->depend.name, INFRQ_ALL);
if(info) {
_alpm_log(PM_LOG_FLOW2, _("pulling %s in the targets list"), info->name);
trans->packages = _alpm_list_add(trans->packages, info);
} else {
_alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping"),
miss->depend.name);
}
}
FREELIST(lp);
lp = _alpm_checkdeps(trans, db, trans->type, trans->packages);
}
} else {
if(data) {
*data = lp;
} else {
FREELIST(lp);
}
RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
}
}
if(trans->flags & PM_TRANS_FLAG_RECURSE) {
_alpm_log(PM_LOG_FLOW1, _("finding removable dependencies"));
trans->packages = _alpm_removedeps(db, trans->packages);
}
_alpm_log(PM_LOG_FLOW1, _("sorting by dependencies"));
lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE);
FREELISTPTR(trans->packages);
trans->packages = lp;
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
}
return(0);
}
static int str_cmp(const void *s1, const void *s2)
{
return(strcmp(s1, s2));
}
int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
{
pmpkg_t *info;
struct stat buf;
pmlist_t *targ, *lp;
char line[PATH_MAX+1];
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
for(targ = trans->packages; targ; targ = targ->next) {
int position = 0;
char pm_install[PATH_MAX];
info = (pmpkg_t*)targ->data;
if(handle->trans->state == STATE_INTERRUPTED) {
break;
}
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, _("removing package %s-%s"), info->name, info->version);
if(info->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
_alpm_runscriptlet(handle->root, pm_install, "pre_remove", info->version, NULL, trans);
}
}
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
int filenum = _alpm_list_count(info->files);
_alpm_log(PM_LOG_FLOW1, _("removing files"));
for(lp = _alpm_list_last(info->files); lp; lp = lp->prev) {
int nb = 0;
double percent;
char *file = lp->data;
char *md5 =_alpm_needbackup(file, info->backup);
char *sha1 =_alpm_needbackup(file, info->backup);
if (position != 0) {
percent = (double)position / filenum;
}
if(md5 && sha1) {
nb = 1;
FREE(md5);
FREE(sha1);
}
if(!nb && trans->type == PM_TRANS_TYPE_UPGRADE) {
if(_alpm_list_is_strin(file, handle->noupgrade)) {
nb = 1;
}
}
snprintf(line, PATH_MAX, "%s%s", handle->root, file);
if(lstat(line, &buf)) {
_alpm_log(PM_LOG_DEBUG, _("file %s does not exist"), file);
continue;
}
if(S_ISDIR(buf.st_mode)) {
if(rmdir(line)) {
_alpm_log(PM_LOG_DEBUG, _("keeping directory %s"), file);
} else {
_alpm_log(PM_LOG_FLOW2, _("removing directory %s"), file);
}
} else {
int skipit = 0;
pmlist_t *j;
for(j = trans->skiplist; j; j = j->next) {
if(!strcmp(file, (char*)j->data)) {
skipit = 1;
}
}
if(skipit) {
_alpm_log(PM_LOG_FLOW2, _("skipping removal of %s as it has moved to another package"),
file);
} else {
if(nb) {
if(trans->type == PM_TRANS_TYPE_UPGRADE) {
} else {
if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s.pacsave", line);
rename(line, newpath);
_alpm_log(PM_LOG_WARNING, _("%s saved as %s"), file, newpath);
alpm_logaction(_("%s saved as %s"), line, newpath);
} else {
_alpm_log(PM_LOG_FLOW2, _("unlinking %s"), file);
if(unlink(line)) {
_alpm_log(PM_LOG_ERROR, _("cannot remove file %s"), file);
}
}
}
} else {
_alpm_log(PM_LOG_FLOW2, _("unlinking %s"), file);
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, (double)(percent * 100), _alpm_list_count(trans->packages), (_alpm_list_count(trans->packages) - _alpm_list_count(targ) +1));
position++;
if(unlink(line)) {
_alpm_log(PM_LOG_ERROR, _("cannot remove file %s"), file);
}
}
}
}
}
}
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
if(info->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
char pm_install[PATH_MAX];
snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
_alpm_runscriptlet(handle->root, pm_install, "post_remove", info->version, NULL, trans);
}
}
_alpm_log(PM_LOG_FLOW1, _("updating database"));
_alpm_log(PM_LOG_FLOW2, _("removing database entry '%s'"), info->name);
if(_alpm_db_remove(db, info) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"), info->name, info->version);
}
if(_alpm_db_remove_pkgfromcache(db, info) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache"), info->name);
}
_alpm_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields"));
for(lp = info->depends; lp; lp = lp->next) {
pmpkg_t *depinfo = NULL;
pmdepend_t depend;
char *data;
if(_alpm_splitdep((char*)lp->data, &depend)) {
continue;
}
if(_alpm_pkg_isin(depend.name, trans->packages)) {
continue;
}
depinfo = _alpm_db_get_pkgfromcache(db, depend.name);
if(depinfo == NULL) {
pmlist_t *provides = _alpm_db_whatprovides(db, depend.name);
if(provides) {
TODO
depinfo = _alpm_db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name);
FREELISTPTR(provides);
}
if(depinfo == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not find dependency '%s'"), depend.name);
continue;
}
}
depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, info->name, str_cmp, (void **)&data);
FREE(data);
_alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), depinfo->name);
if(_alpm_db_write(db, depinfo, INFRQ_DEPENDS)) {
_alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"),
depinfo->name, depinfo->version);
}
}
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 100, _alpm_list_count(trans->packages), (_alpm_list_count(trans->packages) - _alpm_list_count(targ) +1));
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
}
}
if((trans->type != PM_TRANS_TYPE_UPGRADE) && (handle->trans->state != STATE_INTERRUPTED)) {
_alpm_log(PM_LOG_FLOW1, _("running \"ldconfig -r %s\""), handle->root);
_alpm_ldconfig(handle->root);
}
return(0);
}
|