remove.c 20 KB

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