remove.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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/dir.h>
  37. #include <dpkg/myopt.h>
  38. #include <dpkg/triglib.h>
  39. #include "filesdb.h"
  40. #include "main.h"
  41. static void checkforremoval(struct pkginfo *pkgtoremove,
  42. struct pkginfo *pkgdepcheck, /* may be virtual pkg */
  43. int *rokp, struct varbuf *raemsgs) {
  44. struct deppossi *possi;
  45. struct pkginfo *depender;
  46. int before, ok;
  47. for (possi= pkgdepcheck->installed.depended; possi; possi= possi->nextrev) {
  48. if (possi->up->type != dep_depends && possi->up->type != dep_predepends) continue;
  49. depender= possi->up->up;
  50. debug(dbg_depcon,"checking depending package `%s'",depender->name);
  51. if (!(depender->status == stat_installed ||
  52. depender->status == stat_triggerspending ||
  53. depender->status == stat_triggersawaited))
  54. continue;
  55. if (ignore_depends(depender)) {
  56. debug(dbg_depcon, "ignoring depending package '%s'", depender->name);
  57. continue;
  58. }
  59. if (dependtry > 1) { if (findbreakcycle(pkgtoremove)) sincenothing= 0; }
  60. before= raemsgs->used;
  61. ok= dependencies_ok(depender,pkgtoremove,raemsgs);
  62. if (ok == 0 && depender->clientdata->istobe == itb_remove) ok= 1;
  63. if (ok == 1) raemsgs->used= before; /* Don't burble about reasons for deferral */
  64. if (ok < *rokp) *rokp= ok;
  65. }
  66. }
  67. void deferred_remove(struct pkginfo *pkg) {
  68. struct varbuf raemsgs = VARBUF_INIT;
  69. int rok;
  70. struct dependency *dep;
  71. debug(dbg_general,"deferred_remove package %s",pkg->name);
  72. if (pkg->status == stat_notinstalled) {
  73. warning(_("ignoring request to remove %.250s which isn't installed."),
  74. pkg->name);
  75. pkg->clientdata->istobe= itb_normal;
  76. return;
  77. } else if (!f_pending &&
  78. pkg->status == stat_configfiles &&
  79. cipaction->arg != act_purge) {
  80. warning(_("ignoring request to remove %.250s, only the config\n"
  81. " files of which are on the system. Use --purge to remove them too."),
  82. pkg->name);
  83. pkg->clientdata->istobe= itb_normal;
  84. return;
  85. }
  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. varbuf_destroy(&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. varbuf_destroy(&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. bool *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, pkgadmindir());
  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 = false;
  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)) {
  253. *out_foundpostrm = true;
  254. continue;
  255. }
  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. /* Sync the info database directory. */
  265. dir_sync(dsd, fnvb.buf);
  266. pop_cleanup(ehflag_normaltidy); /* closedir */
  267. pkg->status= stat_configfiles;
  268. pkg->installed.essential = false;
  269. modstatdb_note(pkg);
  270. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  271. }
  272. static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) {
  273. struct reversefilelistiter rlistit;
  274. struct fileinlist *leftover;
  275. struct filenamenode *namenode;
  276. static struct varbuf fnvb;
  277. struct stat stab;
  278. modstatdb_note(pkg);
  279. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  280. reversefilelist_init(&rlistit,pkg->clientdata->files);
  281. leftover = NULL;
  282. while ((namenode= reversefilelist_next(&rlistit))) {
  283. struct filenamenode *usenode;
  284. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  285. namenode->name, namenode->flags);
  286. if (namenode->flags & fnnf_old_conff) {
  287. push_leftover(&leftover,namenode);
  288. continue;
  289. }
  290. usenode = namenodetouse(namenode, pkg);
  291. trig_file_activate(usenode, pkg);
  292. varbufreset(&fnvb);
  293. varbufaddstr(&fnvb,instdir);
  294. varbufaddstr(&fnvb, usenode->name);
  295. varbufaddc(&fnvb,0);
  296. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  297. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  298. /* Only delete a directory or a link to one if we're the only
  299. * package which uses it. Other files should only be listed
  300. * in this package (but we don't check).
  301. */
  302. if (hasdirectoryconffiles(namenode,pkg)) {
  303. push_leftover(&leftover,namenode);
  304. continue;
  305. }
  306. if (isdirectoryinuse(namenode,pkg)) continue;
  307. }
  308. debug(dbg_eachfiledetail, "removal_bulk removing `%s'", fnvb.buf);
  309. if (!rmdir(fnvb.buf) || errno == ENOENT || errno == ELOOP) continue;
  310. if (errno == ENOTEMPTY || errno == EEXIST) {
  311. warning(_("while removing %.250s, directory '%.250s' not empty so not removed."),
  312. pkg->name, namenode->name);
  313. push_leftover(&leftover,namenode);
  314. continue;
  315. } else if (errno == EBUSY || errno == EPERM) {
  316. warning(_("while removing %.250s, unable to remove directory '%.250s': "
  317. "%s - directory may be a mount point?"),
  318. pkg->name, namenode->name, strerror(errno));
  319. push_leftover(&leftover,namenode);
  320. continue;
  321. }
  322. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  323. push_leftover(&leftover,namenode);
  324. continue;
  325. }
  326. write_filelist_except(pkg,leftover,0);
  327. modstatdb_note(pkg);
  328. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  329. }
  330. static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
  331. static const char *const removeconffexts[] = { REMOVECONFFEXTS, NULL };
  332. int r, removevbbase;
  333. int conffnameused, conffbasenamelen;
  334. char *conffbasename;
  335. struct conffile *conff, **lconffp;
  336. struct fileinlist *searchfile;
  337. DIR *dsd;
  338. struct dirent *de;
  339. char *p;
  340. const char *const *ext;
  341. printf(_("Purging configuration files for %s ...\n"),pkg->name);
  342. log_action("purge", pkg);
  343. trig_activate_packageprocessing(pkg);
  344. ensure_packagefiles_available(pkg); /* We may have modified this above. */
  345. /* We're about to remove the configuration, so remove the note
  346. * about which version it was ...
  347. */
  348. blankversion(&pkg->configversion);
  349. modstatdb_note(pkg);
  350. /* Remove from our list any conffiles that aren't ours any more or
  351. * are involved in diversions, except if we are the package doing the
  352. * diverting.
  353. */
  354. for (lconffp = &pkg->installed.conffiles; (conff = *lconffp) != NULL; ) {
  355. for (searchfile= pkg->clientdata->files;
  356. searchfile && strcmp(searchfile->namenode->name,conff->name);
  357. searchfile= searchfile->next);
  358. if (!searchfile) {
  359. debug(dbg_conff,"removal_bulk conffile not ours any more `%s'",conff->name);
  360. *lconffp= conff->next;
  361. } else if (searchfile->namenode->divert &&
  362. (searchfile->namenode->divert->camefrom ||
  363. (searchfile->namenode->divert->useinstead &&
  364. searchfile->namenode->divert->pkg != pkg))) {
  365. debug(dbg_conff, "removal_bulk conffile '%s' ignored due to diversion",
  366. conff->name);
  367. *lconffp= conff->next;
  368. } else {
  369. debug(dbg_conffdetail,"removal_bulk set to new conffile `%s'",conff->name);
  370. conff->hash = NEWCONFFILEFLAG;
  371. lconffp= &conff->next;
  372. }
  373. }
  374. modstatdb_note(pkg);
  375. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  376. static struct varbuf fnvb, removevb;
  377. if (conff->obsolete) {
  378. debug(dbg_conffdetail, "removal_bulk conffile obsolete %s",
  379. conff->name);
  380. }
  381. varbufreset(&fnvb);
  382. r= conffderef(pkg, &fnvb, conff->name);
  383. debug(dbg_conffdetail, "removal_bulk conffile `%s' (= `%s')",
  384. conff->name, r == -1 ? "<r==-1>" : fnvb.buf);
  385. if (r == -1) continue;
  386. conffnameused= fnvb.used-1;
  387. if (unlink(fnvb.buf) && errno != ENOENT && errno != ENOTDIR)
  388. ohshite(_("cannot remove old config file `%.250s' (= `%.250s')"),
  389. conff->name, fnvb.buf);
  390. p= strrchr(fnvb.buf,'/'); if (!p) continue;
  391. *p = '\0';
  392. varbufreset(&removevb);
  393. varbufaddstr(&removevb,fnvb.buf);
  394. varbufaddc(&removevb,'/');
  395. removevbbase= removevb.used;
  396. varbufaddc(&removevb,0);
  397. dsd= opendir(removevb.buf);
  398. if (!dsd) {
  399. int e=errno;
  400. debug(dbg_conffdetail, "removal_bulk conffile no dsd %s %s",
  401. fnvb.buf, strerror(e)); errno= e;
  402. if (errno == ENOENT || errno == ENOTDIR) continue;
  403. ohshite(_("cannot read config file dir `%.250s' (from `%.250s')"),
  404. fnvb.buf, conff->name);
  405. }
  406. debug(dbg_conffdetail, "removal_bulk conffile cleaning dsd %s", fnvb.buf);
  407. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  408. *p= '/';
  409. conffbasenamelen= strlen(++p);
  410. conffbasename= fnvb.buf+conffnameused-conffbasenamelen;
  411. while ((de = readdir(dsd)) != NULL) {
  412. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry=`%s'"
  413. " conffbasename=`%s' conffnameused=%d conffbasenamelen=%d",
  414. de->d_name, conffbasename, conffnameused, conffbasenamelen);
  415. if (!strncmp(de->d_name,conffbasename,conffbasenamelen)) {
  416. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts right");
  417. for (ext= removeconffexts; *ext; ext++)
  418. if (!strcmp(*ext,de->d_name+conffbasenamelen)) goto yes_remove;
  419. p= de->d_name+conffbasenamelen;
  420. if (*p++ == '~') {
  421. while (*p && cisdigit(*p)) p++;
  422. if (*p == '~' && !*++p) goto yes_remove;
  423. }
  424. }
  425. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts wrong");
  426. if (de->d_name[0] == '#' &&
  427. !strncmp(de->d_name+1,conffbasename,conffbasenamelen) &&
  428. !strcmp(de->d_name+1+conffbasenamelen,"#"))
  429. goto yes_remove;
  430. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry not it");
  431. continue;
  432. yes_remove:
  433. removevb.used= removevbbase;
  434. varbufaddstr(&removevb,de->d_name); varbufaddc(&removevb,0);
  435. debug(dbg_conffdetail, "removal_bulk conffile dsd entry removing `%s'",
  436. removevb.buf);
  437. if (unlink(removevb.buf) && errno != ENOENT && errno != ENOTDIR)
  438. ohshite(_("cannot remove old backup config file `%.250s' (of `%.250s')"),
  439. removevb.buf, conff->name);
  440. }
  441. pop_cleanup(ehflag_normaltidy); /* closedir */
  442. }
  443. pkg->installed.conffiles = NULL;
  444. modstatdb_note(pkg);
  445. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  446. "purge", NULL);
  447. }
  448. void removal_bulk(struct pkginfo *pkg) {
  449. /* This is used both by deferred_remove in this file, and at
  450. * the end of process_archive in archives.c if it needs to finish
  451. * removing a conflicting package.
  452. */
  453. int pkgnameused;
  454. bool foundpostrm = false;
  455. const char *postrmfilename;
  456. debug(dbg_general,"removal_bulk package %s",pkg->name);
  457. if (pkg->status == stat_halfinstalled || pkg->status == stat_unpacked) {
  458. removal_bulk_remove_files(pkg, &foundpostrm);
  459. } else {
  460. struct stat stab;
  461. postrmfilename= pkgadminfile(pkg,POSTRMFILE);
  462. if (!lstat(postrmfilename, &stab))
  463. foundpostrm = true;
  464. else if (errno == ENOENT)
  465. foundpostrm = false;
  466. else ohshite(_("unable to check existence of `%.250s'"),postrmfilename);
  467. }
  468. debug(dbg_general, "removal_bulk purging? foundpostrm=%d",foundpostrm);
  469. if (!foundpostrm && !pkg->installed.conffiles) {
  470. /* If there are no config files and no postrm script then we
  471. * go straight into `purge'.
  472. */
  473. debug(dbg_general, "removal_bulk no postrm, no conffiles, purging");
  474. pkg->want= want_purge;
  475. blankversion(&pkg->configversion);
  476. } else if (pkg->want == want_purge) {
  477. removal_bulk_remove_configfiles(pkg);
  478. }
  479. if (pkg->want == want_purge) {
  480. /* ie, either of the two branches above. */
  481. static struct varbuf fnvb;
  482. /* retry empty directories, and warn on any leftovers that aren't */
  483. removal_bulk_remove_leftover_dirs(pkg);
  484. varbufreset(&fnvb);
  485. varbufaddstr(&fnvb, pkgadmindir());
  486. varbufaddstr(&fnvb,pkg->name);
  487. pkgnameused= fnvb.used;
  488. varbufaddstr(&fnvb,"." LISTFILE);
  489. varbufaddc(&fnvb,0);
  490. debug(dbg_general, "removal_bulk purge done, removing list `%s'",fnvb.buf);
  491. if (unlink(fnvb.buf) && errno != ENOENT) ohshite(_("cannot remove old files list"));
  492. fnvb.used= pkgnameused;
  493. varbufaddstr(&fnvb,"." POSTRMFILE);
  494. varbufaddc(&fnvb,0);
  495. debug(dbg_general, "removal_bulk purge done, removing postrm `%s'",fnvb.buf);
  496. if (unlink(fnvb.buf) && errno != ENOENT) ohshite(_("can't remove old postrm script"));
  497. pkg->status= stat_notinstalled;
  498. pkg->want = want_unknown;
  499. /* This will mess up reverse links, but if we follow them
  500. * we won't go back because pkg->status is stat_notinstalled.
  501. */
  502. blankpackageperfile(&pkg->installed);
  503. }
  504. pkg->eflag = eflag_ok;
  505. modstatdb_note(pkg);
  506. debug(dbg_general, "removal done");
  507. }