remove.c 20 KB

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