remove.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * dpkg - main program for package management
  3. * remove.c - functionality for removing packages
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <assert.h>
  26. #include <errno.h>
  27. #include <ctype.h>
  28. #include <string.h>
  29. #include <fcntl.h>
  30. #include <dirent.h>
  31. #include <unistd.h>
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <dpkg/i18n.h>
  35. #include <dpkg/dpkg.h>
  36. #include <dpkg/dpkg-db.h>
  37. #include <dpkg/myopt.h>
  38. #include "filesdb.h"
  39. #include "main.h"
  40. static void checkforremoval(struct pkginfo *pkgtoremove,
  41. struct pkginfo *pkgdepcheck, /* may be virtual pkg */
  42. int *rokp, struct varbuf *raemsgs) {
  43. struct deppossi *possi;
  44. struct pkginfo *depender;
  45. int before, ok;
  46. for (possi= pkgdepcheck->installed.depended; possi; possi= possi->nextrev) {
  47. if (possi->up->type != dep_depends && possi->up->type != dep_predepends) continue;
  48. depender= possi->up->up;
  49. debug(dbg_depcon,"checking depending package `%s'",depender->name);
  50. if (!(depender->status == stat_installed ||
  51. depender->status == stat_triggerspending ||
  52. depender->status == stat_triggersawaited))
  53. continue;
  54. if (ignore_depends(depender)) {
  55. debug(dbg_depcon,"ignoring depending package `%s'\n",depender->name);
  56. continue;
  57. }
  58. if (dependtry > 1) { if (findbreakcycle(pkgtoremove)) sincenothing= 0; }
  59. before= raemsgs->used;
  60. ok= dependencies_ok(depender,pkgtoremove,raemsgs);
  61. if (ok == 0 && depender->clientdata->istobe == itb_remove) ok= 1;
  62. if (ok == 1) raemsgs->used= before; /* Don't burble about reasons for deferral */
  63. if (ok < *rokp) *rokp= ok;
  64. }
  65. }
  66. void deferred_remove(struct pkginfo *pkg) {
  67. struct varbuf raemsgs = VARBUF_INIT;
  68. int rok;
  69. struct dependency *dep;
  70. debug(dbg_general,"deferred_remove package %s",pkg->name);
  71. if (pkg->status == stat_notinstalled) {
  72. warning(_("ignoring request to remove %.250s which isn't installed."),
  73. pkg->name);
  74. pkg->clientdata->istobe= itb_normal;
  75. return;
  76. } else if (!f_pending &&
  77. pkg->status == stat_configfiles &&
  78. cipaction->arg != act_purge) {
  79. warning(_("ignoring request to remove %.250s, only the config\n"
  80. " files of which are on the system. Use --purge to remove them too."),
  81. pkg->name);
  82. pkg->clientdata->istobe= itb_normal;
  83. return;
  84. }
  85. assert(pkg->installed.valid);
  86. if (pkg->installed.essential && pkg->status != stat_configfiles)
  87. forcibleerr(fc_removeessential, _("This is an essential package -"
  88. " it should not be removed."));
  89. if (!f_pending)
  90. pkg->want= (cipaction->arg == act_purge) ? want_purge : want_deinstall;
  91. if (!f_noact) modstatdb_note(pkg);
  92. debug(dbg_general,"checking dependencies for remove `%s'",pkg->name);
  93. rok= 2;
  94. checkforremoval(pkg,pkg,&rok,&raemsgs);
  95. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  96. if (dep->type != dep_provides) continue;
  97. debug(dbg_depcon,"checking virtual package `%s'",dep->list->ed->name);
  98. checkforremoval(pkg,dep->list->ed,&rok,&raemsgs);
  99. }
  100. if (rok == 1) {
  101. varbuffree(&raemsgs);
  102. pkg->clientdata->istobe= itb_remove;
  103. add_to_queue(pkg);
  104. return;
  105. } else if (rok == 0) {
  106. sincenothing= 0;
  107. varbufaddc(&raemsgs,0);
  108. fprintf(stderr,
  109. _("dpkg: dependency problems prevent removal of %s:\n%s"),
  110. pkg->name, raemsgs.buf);
  111. ohshit(_("dependency problems - not removing"));
  112. } else if (raemsgs.used) {
  113. varbufaddc(&raemsgs,0);
  114. fprintf(stderr,
  115. _("dpkg: %s: dependency problems, but removing anyway as you requested:\n%s"),
  116. pkg->name, raemsgs.buf);
  117. }
  118. varbuffree(&raemsgs);
  119. sincenothing= 0;
  120. if (pkg->eflag & eflag_reinstreq)
  121. forcibleerr(fc_removereinstreq,
  122. _("Package is in a very bad inconsistent state - you should\n"
  123. " reinstall it before attempting a removal."));
  124. ensure_allinstfiles_available();
  125. filesdbinit();
  126. if (f_noact) {
  127. printf(_("Would remove or purge %s ...\n"),pkg->name);
  128. pkg->status= stat_notinstalled;
  129. pkg->clientdata->istobe= itb_normal;
  130. return;
  131. }
  132. oldconffsetflags(pkg->installed.conffiles);
  133. printf(_("Removing %s ...\n"),pkg->name);
  134. log_action("remove", pkg);
  135. trig_activate_packageprocessing(pkg);
  136. if (pkg->status >= stat_halfconfigured) {
  137. static enum pkgstatus oldpkgstatus;
  138. oldpkgstatus= pkg->status;
  139. pkg->status= stat_halfconfigured;
  140. modstatdb_note(pkg);
  141. push_cleanup(cu_prermremove, ~ehflag_normaltidy, NULL, 0, 2,
  142. (void *)pkg, (void *)&oldpkgstatus);
  143. maintainer_script_installed(pkg, PRERMFILE, "pre-removal",
  144. "remove", NULL);
  145. pkg->status= stat_unpacked; /* Will turn into halfinstalled soon ... */
  146. }
  147. removal_bulk(pkg);
  148. }
  149. static void push_leftover(struct fileinlist **leftoverp,
  150. struct filenamenode *namenode) {
  151. struct fileinlist *newentry;
  152. newentry= nfmalloc(sizeof(struct fileinlist));
  153. newentry->next= *leftoverp;
  154. newentry->namenode= namenode;
  155. *leftoverp= newentry;
  156. }
  157. static void removal_bulk_remove_files(
  158. struct pkginfo *pkg,
  159. int *out_foundpostrm)
  160. {
  161. int before;
  162. int infodirbaseused;
  163. struct reversefilelistiter rlistit;
  164. struct fileinlist *leftover;
  165. struct filenamenode *namenode;
  166. static struct varbuf fnvb;
  167. DIR *dsd;
  168. struct dirent *de;
  169. struct stat stab;
  170. pkg->status= stat_halfinstalled;
  171. modstatdb_note(pkg);
  172. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  173. reversefilelist_init(&rlistit,pkg->clientdata->files);
  174. leftover = NULL;
  175. while ((namenode= reversefilelist_next(&rlistit))) {
  176. struct filenamenode *usenode;
  177. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  178. namenode->name, namenode->flags);
  179. if (namenode->flags & fnnf_old_conff) {
  180. push_leftover(&leftover,namenode);
  181. continue;
  182. }
  183. usenode = namenodetouse(namenode, pkg);
  184. trig_file_activate(usenode, pkg);
  185. varbufreset(&fnvb);
  186. varbufaddstr(&fnvb,instdir);
  187. varbufaddstr(&fnvb, usenode->name);
  188. before= fnvb.used;
  189. varbufaddstr(&fnvb,DPKGTEMPEXT);
  190. varbufaddc(&fnvb,0);
  191. debug(dbg_eachfiledetail, "removal_bulk cleaning temp `%s'", fnvb.buf);
  192. ensure_pathname_nonexisting(fnvb.buf);
  193. fnvb.used= before;
  194. varbufaddstr(&fnvb,DPKGNEWEXT);
  195. varbufaddc(&fnvb,0);
  196. debug(dbg_eachfiledetail, "removal_bulk cleaning new `%s'", fnvb.buf);
  197. ensure_pathname_nonexisting(fnvb.buf);
  198. fnvb.used= before;
  199. varbufaddc(&fnvb,0);
  200. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  201. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  202. /* Only delete a directory or a link to one if we're the only
  203. * package which uses it. Other files should only be listed
  204. * in this package (but we don't check).
  205. */
  206. if (hasdirectoryconffiles(namenode,pkg)) {
  207. push_leftover(&leftover,namenode);
  208. continue;
  209. }
  210. if (isdirectoryinuse(namenode,pkg)) continue;
  211. }
  212. debug(dbg_eachfiledetail, "removal_bulk removing `%s'", fnvb.buf);
  213. if (!rmdir(fnvb.buf) || errno == ENOENT || errno == ELOOP) continue;
  214. if (errno == ENOTEMPTY || errno == EEXIST) {
  215. debug(dbg_eachfiledetail, "removal_bulk `%s' was not empty, will try again later",
  216. fnvb.buf);
  217. push_leftover(&leftover,namenode);
  218. continue;
  219. } else if (errno == EBUSY || errno == EPERM) {
  220. warning(_("while removing %.250s, unable to remove directory '%.250s': "
  221. "%s - directory may be a mount point?"),
  222. pkg->name, namenode->name, strerror(errno));
  223. push_leftover(&leftover,namenode);
  224. continue;
  225. }
  226. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  227. debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);
  228. if (secure_unlink(fnvb.buf))
  229. ohshite(_("unable to securely remove '%.250s'"), fnvb.buf);
  230. }
  231. write_filelist_except(pkg,leftover,0);
  232. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  233. "remove", NULL);
  234. varbufreset(&fnvb);
  235. varbufaddstr(&fnvb,admindir);
  236. varbufaddstr(&fnvb,"/" INFODIR);
  237. infodirbaseused= fnvb.used;
  238. varbufaddc(&fnvb,0);
  239. dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
  240. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  241. *out_foundpostrm= 0;
  242. debug(dbg_general, "removal_bulk cleaning info directory");
  243. while ((de = readdir(dsd)) != NULL) {
  244. char *p;
  245. debug(dbg_veryverbose, "removal_bulk info file `%s'", de->d_name);
  246. if (de->d_name[0] == '.') continue;
  247. p= strrchr(de->d_name,'.'); if (!p) continue;
  248. if (strlen(pkg->name) != (size_t)(p-de->d_name) ||
  249. strncmp(de->d_name,pkg->name,p-de->d_name)) continue;
  250. debug(dbg_stupidlyverbose, "removal_bulk info this pkg");
  251. /* We need the postrm and list files for --purge. */
  252. if (!strcmp(p+1,LISTFILE)) continue;
  253. if (!strcmp(p+1,POSTRMFILE)) { *out_foundpostrm=1; continue; }
  254. debug(dbg_stupidlyverbose, "removal_bulk info not postrm or list");
  255. fnvb.used= infodirbaseused;
  256. varbufaddstr(&fnvb,de->d_name);
  257. varbufaddc(&fnvb,0);
  258. if (unlink(fnvb.buf))
  259. ohshite(_("unable to delete control info file `%.250s'"),fnvb.buf);
  260. debug(dbg_scripts, "removal_bulk info unlinked %s",fnvb.buf);
  261. }
  262. pop_cleanup(ehflag_normaltidy); /* closedir */
  263. pkg->status= stat_configfiles;
  264. pkg->installed.essential= 0;
  265. modstatdb_note(pkg);
  266. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  267. }
  268. static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) {
  269. struct reversefilelistiter rlistit;
  270. struct fileinlist *leftover;
  271. struct filenamenode *namenode;
  272. static struct varbuf fnvb;
  273. struct stat stab;
  274. modstatdb_note(pkg);
  275. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  276. reversefilelist_init(&rlistit,pkg->clientdata->files);
  277. leftover = NULL;
  278. while ((namenode= reversefilelist_next(&rlistit))) {
  279. struct filenamenode *usenode;
  280. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  281. namenode->name, namenode->flags);
  282. if (namenode->flags & fnnf_old_conff) {
  283. push_leftover(&leftover,namenode);
  284. continue;
  285. }
  286. usenode = namenodetouse(namenode, pkg);
  287. trig_file_activate(usenode, pkg);
  288. varbufreset(&fnvb);
  289. varbufaddstr(&fnvb,instdir);
  290. varbufaddstr(&fnvb, usenode->name);
  291. varbufaddc(&fnvb,0);
  292. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  293. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  294. /* Only delete a directory or a link to one if we're the only
  295. * package which uses it. Other files should only be listed
  296. * in this package (but we don't check).
  297. */
  298. if (hasdirectoryconffiles(namenode,pkg)) {
  299. push_leftover(&leftover,namenode);
  300. continue;
  301. }
  302. if (isdirectoryinuse(namenode,pkg)) continue;
  303. }
  304. debug(dbg_eachfiledetail, "removal_bulk removing `%s'", fnvb.buf);
  305. if (!rmdir(fnvb.buf) || errno == ENOENT || errno == ELOOP) continue;
  306. if (errno == ENOTEMPTY || errno == EEXIST) {
  307. warning(_("while removing %.250s, directory '%.250s' not empty so not removed."),
  308. pkg->name, namenode->name);
  309. push_leftover(&leftover,namenode);
  310. continue;
  311. } else if (errno == EBUSY || errno == EPERM) {
  312. warning(_("while removing %.250s, unable to remove directory '%.250s': "
  313. "%s - directory may be a mount point?"),
  314. pkg->name, namenode->name, strerror(errno));
  315. push_leftover(&leftover,namenode);
  316. continue;
  317. }
  318. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  319. push_leftover(&leftover,namenode);
  320. continue;
  321. }
  322. write_filelist_except(pkg,leftover,0);
  323. modstatdb_note(pkg);
  324. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  325. }
  326. static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
  327. static const char *const removeconffexts[] = { REMOVECONFFEXTS, NULL };
  328. int r, removevbbase;
  329. int conffnameused, conffbasenamelen;
  330. char *conffbasename;
  331. struct conffile *conff, **lconffp;
  332. struct fileinlist *searchfile;
  333. DIR *dsd;
  334. struct dirent *de;
  335. char *p;
  336. const char *const *ext;
  337. printf(_("Purging configuration files for %s ...\n"),pkg->name);
  338. log_action("purge", pkg);
  339. trig_activate_packageprocessing(pkg);
  340. ensure_packagefiles_available(pkg); /* We may have modified this above. */
  341. /* We're about to remove the configuration, so remove the note
  342. * about which version it was ...
  343. */
  344. blankversion(&pkg->configversion);
  345. modstatdb_note(pkg);
  346. /* Remove from our list any conffiles that aren't ours any more or
  347. * are involved in diversions, except if we are the package doing the
  348. * diverting.
  349. */
  350. for (lconffp = &pkg->installed.conffiles; (conff = *lconffp) != NULL; ) {
  351. for (searchfile= pkg->clientdata->files;
  352. searchfile && strcmp(searchfile->namenode->name,conff->name);
  353. searchfile= searchfile->next);
  354. if (!searchfile) {
  355. debug(dbg_conff,"removal_bulk conffile not ours any more `%s'",conff->name);
  356. *lconffp= conff->next;
  357. } else if (searchfile->namenode->divert &&
  358. (searchfile->namenode->divert->camefrom ||
  359. (searchfile->namenode->divert->useinstead &&
  360. searchfile->namenode->divert->pkg != pkg))) {
  361. debug(dbg_conff,"removal_bulk conffile `%s' ignored due to diversion\n",
  362. conff->name);
  363. *lconffp= conff->next;
  364. } else {
  365. debug(dbg_conffdetail,"removal_bulk set to new conffile `%s'",conff->name);
  366. conff->hash = NEWCONFFILEFLAG;
  367. lconffp= &conff->next;
  368. }
  369. }
  370. modstatdb_note(pkg);
  371. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  372. static struct varbuf fnvb, removevb;
  373. if (conff->obsolete) {
  374. debug(dbg_conffdetail, "removal_bulk conffile obsolete %s",
  375. conff->name);
  376. }
  377. varbufreset(&fnvb);
  378. r= conffderef(pkg, &fnvb, conff->name);
  379. debug(dbg_conffdetail, "removal_bulk conffile `%s' (= `%s')",
  380. conff->name, r == -1 ? "<r==-1>" : fnvb.buf);
  381. if (r == -1) continue;
  382. conffnameused= fnvb.used-1;
  383. if (unlink(fnvb.buf) && errno != ENOENT && errno != ENOTDIR)
  384. ohshite(_("cannot remove old config file `%.250s' (= `%.250s')"),
  385. conff->name, fnvb.buf);
  386. p= strrchr(fnvb.buf,'/'); if (!p) continue;
  387. *p = '\0';
  388. varbufreset(&removevb);
  389. varbufaddstr(&removevb,fnvb.buf);
  390. varbufaddc(&removevb,'/');
  391. removevbbase= removevb.used;
  392. varbufaddc(&removevb,0);
  393. dsd= opendir(removevb.buf);
  394. if (!dsd) {
  395. int e=errno;
  396. debug(dbg_conffdetail, "removal_bulk conffile no dsd %s %s",
  397. fnvb.buf, strerror(e)); errno= e;
  398. if (errno == ENOENT || errno == ENOTDIR) continue;
  399. ohshite(_("cannot read config file dir `%.250s' (from `%.250s')"),
  400. fnvb.buf, conff->name);
  401. }
  402. debug(dbg_conffdetail, "removal_bulk conffile cleaning dsd %s", fnvb.buf);
  403. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  404. *p= '/';
  405. conffbasenamelen= strlen(++p);
  406. conffbasename= fnvb.buf+conffnameused-conffbasenamelen;
  407. while ((de = readdir(dsd)) != NULL) {
  408. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry=`%s'"
  409. " conffbasename=`%s' conffnameused=%d conffbasenamelen=%d",
  410. de->d_name, conffbasename, conffnameused, conffbasenamelen);
  411. if (!strncmp(de->d_name,conffbasename,conffbasenamelen)) {
  412. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts right");
  413. for (ext= removeconffexts; *ext; ext++)
  414. if (!strcmp(*ext,de->d_name+conffbasenamelen)) goto yes_remove;
  415. p= de->d_name+conffbasenamelen;
  416. if (*p++ == '~') {
  417. while (*p && cisdigit(*p)) p++;
  418. if (*p == '~' && !*++p) goto yes_remove;
  419. }
  420. }
  421. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts wrong");
  422. if (de->d_name[0] == '#' &&
  423. !strncmp(de->d_name+1,conffbasename,conffbasenamelen) &&
  424. !strcmp(de->d_name+1+conffbasenamelen,"#"))
  425. goto yes_remove;
  426. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry not it");
  427. continue;
  428. yes_remove:
  429. removevb.used= removevbbase;
  430. varbufaddstr(&removevb,de->d_name); varbufaddc(&removevb,0);
  431. debug(dbg_conffdetail, "removal_bulk conffile dsd entry removing `%s'",
  432. removevb.buf);
  433. if (unlink(removevb.buf) && errno != ENOENT && errno != ENOTDIR)
  434. ohshite(_("cannot remove old backup config file `%.250s' (of `%.250s')"),
  435. removevb.buf, conff->name);
  436. }
  437. pop_cleanup(ehflag_normaltidy); /* closedir */
  438. }
  439. pkg->installed.conffiles = NULL;
  440. modstatdb_note(pkg);
  441. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  442. "purge", NULL);
  443. }
  444. void removal_bulk(struct pkginfo *pkg) {
  445. /* This is used both by deferred_remove in this file, and at
  446. * the end of process_archive in archives.c if it needs to finish
  447. * removing a conflicting package.
  448. */
  449. int pkgnameused;
  450. int foundpostrm= 0;
  451. const char *postrmfilename;
  452. debug(dbg_general,"removal_bulk package %s",pkg->name);
  453. if (pkg->status == stat_halfinstalled || pkg->status == stat_unpacked) {
  454. removal_bulk_remove_files(pkg, &foundpostrm);
  455. } else {
  456. struct stat stab;
  457. postrmfilename= pkgadminfile(pkg,POSTRMFILE);
  458. if (!lstat(postrmfilename,&stab)) foundpostrm= 1;
  459. else if (errno == ENOENT) foundpostrm= 0;
  460. else ohshite(_("unable to check existence of `%.250s'"),postrmfilename);
  461. }
  462. debug(dbg_general, "removal_bulk purging? foundpostrm=%d",foundpostrm);
  463. if (!foundpostrm && !pkg->installed.conffiles) {
  464. /* If there are no config files and no postrm script then we
  465. * go straight into `purge'.
  466. */
  467. debug(dbg_general, "removal_bulk no postrm, no conffiles, purging");
  468. pkg->want= want_purge;
  469. blankversion(&pkg->configversion);
  470. } else if (pkg->want == want_purge) {
  471. removal_bulk_remove_configfiles(pkg);
  472. }
  473. if (pkg->want == want_purge) {
  474. /* ie, either of the two branches above. */
  475. static struct varbuf fnvb;
  476. /* retry empty directories, and warn on any leftovers that aren't */
  477. removal_bulk_remove_leftover_dirs(pkg);
  478. varbufreset(&fnvb);
  479. varbufaddstr(&fnvb,admindir);
  480. varbufaddstr(&fnvb,"/" INFODIR);
  481. varbufaddstr(&fnvb,pkg->name);
  482. pkgnameused= fnvb.used;
  483. varbufaddstr(&fnvb,"." LISTFILE);
  484. varbufaddc(&fnvb,0);
  485. debug(dbg_general, "removal_bulk purge done, removing list `%s'",fnvb.buf);
  486. if (unlink(fnvb.buf) && errno != ENOENT) ohshite(_("cannot remove old files list"));
  487. fnvb.used= pkgnameused;
  488. varbufaddstr(&fnvb,"." POSTRMFILE);
  489. varbufaddc(&fnvb,0);
  490. debug(dbg_general, "removal_bulk purge done, removing postrm `%s'",fnvb.buf);
  491. if (unlink(fnvb.buf) && errno != ENOENT) ohshite(_("can't remove old postrm script"));
  492. pkg->status= stat_notinstalled;
  493. pkg->want = want_unknown;
  494. /* This will mess up reverse links, but if we follow them
  495. * we won't go back because pkg->status is stat_notinstalled.
  496. */
  497. blankpackageperfile(&pkg->installed);
  498. }
  499. pkg->eflag = eflag_ok;
  500. modstatdb_note(pkg);
  501. debug(dbg_general, "removal done");
  502. }