remove.c 20 KB

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