remove.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 <errno.h>
  25. #include <ctype.h>
  26. #include <string.h>
  27. #include <fcntl.h>
  28. #include <dirent.h>
  29. #include <unistd.h>
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <dpkg/i18n.h>
  33. #include <dpkg/dpkg.h>
  34. #include <dpkg/dpkg-db.h>
  35. #include <dpkg/dir.h>
  36. #include <dpkg/myopt.h>
  37. #include <dpkg/triglib.h>
  38. #include "infodb.h"
  39. #include "filesdb.h"
  40. #include "main.h"
  41. /*
  42. * pkgdepcheck may be a virtual pkg.
  43. */
  44. static void checkforremoval(struct pkginfo *pkgtoremove,
  45. struct pkginfo *pkgdepcheck,
  46. int *rokp, struct varbuf *raemsgs) {
  47. struct deppossi *possi;
  48. struct pkginfo *depender;
  49. int before, ok;
  50. for (possi = pkgdepcheck->installed.depended; possi; possi = possi->rev_next) {
  51. if (possi->up->type != dep_depends && possi->up->type != dep_predepends) continue;
  52. depender= possi->up->up;
  53. debug(dbg_depcon,"checking depending package `%s'",depender->name);
  54. if (!(depender->status == stat_installed ||
  55. depender->status == stat_triggerspending ||
  56. depender->status == stat_triggersawaited))
  57. continue;
  58. if (ignore_depends(depender)) {
  59. debug(dbg_depcon, "ignoring depending package '%s'", depender->name);
  60. continue;
  61. }
  62. if (dependtry > 1) { if (findbreakcycle(pkgtoremove)) sincenothing= 0; }
  63. before= raemsgs->used;
  64. ok= dependencies_ok(depender,pkgtoremove,raemsgs);
  65. if (ok == 0 && depender->clientdata->istobe == itb_remove) ok= 1;
  66. if (ok == 1)
  67. /* Don't burble about reasons for deferral. */
  68. varbuf_trunc(raemsgs, before);
  69. if (ok < *rokp) *rokp= ok;
  70. }
  71. }
  72. void deferred_remove(struct pkginfo *pkg) {
  73. struct varbuf raemsgs = VARBUF_INIT;
  74. int rok;
  75. struct dependency *dep;
  76. debug(dbg_general,"deferred_remove package %s",pkg->name);
  77. if (pkg->status == stat_notinstalled) {
  78. warning(_("ignoring request to remove %.250s which isn't installed."),
  79. pkg->name);
  80. pkg->clientdata->istobe= itb_normal;
  81. return;
  82. } else if (!f_pending &&
  83. pkg->status == stat_configfiles &&
  84. cipaction->arg_int != act_purge) {
  85. warning(_("ignoring request to remove %.250s, only the config\n"
  86. " files of which are on the system. Use --purge to remove them too."),
  87. pkg->name);
  88. pkg->clientdata->istobe= itb_normal;
  89. return;
  90. }
  91. if (pkg->installed.essential && pkg->status != stat_configfiles)
  92. forcibleerr(fc_removeessential, _("This is an essential package -"
  93. " it should not be removed."));
  94. if (!f_pending)
  95. pkg->want = (cipaction->arg_int == act_purge) ? want_purge : want_deinstall;
  96. if (!f_noact) modstatdb_note(pkg);
  97. debug(dbg_general,"checking dependencies for remove `%s'",pkg->name);
  98. rok= 2;
  99. checkforremoval(pkg,pkg,&rok,&raemsgs);
  100. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  101. if (dep->type != dep_provides) continue;
  102. debug(dbg_depcon,"checking virtual package `%s'",dep->list->ed->name);
  103. checkforremoval(pkg,dep->list->ed,&rok,&raemsgs);
  104. }
  105. if (rok == 1) {
  106. varbuf_destroy(&raemsgs);
  107. pkg->clientdata->istobe= itb_remove;
  108. add_to_queue(pkg);
  109. return;
  110. } else if (rok == 0) {
  111. sincenothing= 0;
  112. varbuf_end_str(&raemsgs);
  113. fprintf(stderr,
  114. _("dpkg: dependency problems prevent removal of %s:\n%s"),
  115. pkg->name, raemsgs.buf);
  116. ohshit(_("dependency problems - not removing"));
  117. } else if (raemsgs.used) {
  118. varbuf_end_str(&raemsgs);
  119. fprintf(stderr,
  120. _("dpkg: %s: dependency problems, but removing anyway as you requested:\n%s"),
  121. pkg->name, raemsgs.buf);
  122. }
  123. varbuf_destroy(&raemsgs);
  124. sincenothing= 0;
  125. if (pkg->eflag & eflag_reinstreq)
  126. forcibleerr(fc_removereinstreq,
  127. _("Package is in a very bad inconsistent state - you should\n"
  128. " reinstall it before attempting a removal."));
  129. ensure_allinstfiles_available();
  130. filesdbinit();
  131. if (f_noact) {
  132. printf(_("Would remove or purge %s ...\n"),pkg->name);
  133. pkg->status= stat_notinstalled;
  134. pkg->clientdata->istobe= itb_normal;
  135. return;
  136. }
  137. oldconffsetflags(pkg->installed.conffiles);
  138. printf(_("Removing %s ...\n"),pkg->name);
  139. log_action("remove", pkg);
  140. trig_activate_packageprocessing(pkg);
  141. if (pkg->status >= stat_halfconfigured) {
  142. static enum pkgstatus oldpkgstatus;
  143. oldpkgstatus= pkg->status;
  144. pkg->status= stat_halfconfigured;
  145. modstatdb_note(pkg);
  146. push_cleanup(cu_prermremove, ~ehflag_normaltidy, NULL, 0, 2,
  147. (void *)pkg, (void *)&oldpkgstatus);
  148. maintainer_script_installed(pkg, PRERMFILE, "pre-removal",
  149. "remove", NULL);
  150. /* Will turn into ‘half-installed’ soon ... */
  151. pkg->status = stat_unpacked;
  152. }
  153. removal_bulk(pkg);
  154. }
  155. static void push_leftover(struct fileinlist **leftoverp,
  156. struct filenamenode *namenode) {
  157. struct fileinlist *newentry;
  158. newentry= nfmalloc(sizeof(struct fileinlist));
  159. newentry->next= *leftoverp;
  160. newentry->namenode= namenode;
  161. *leftoverp= newentry;
  162. }
  163. static void
  164. removal_bulk_remove_file(const char *filename, const char *filetype)
  165. {
  166. /* We need the postrm and list files for --purge. */
  167. if (strcmp(filetype, LISTFILE) == 0 ||
  168. strcmp(filetype, POSTRMFILE) == 0)
  169. return;
  170. debug(dbg_stupidlyverbose, "removal_bulk info not postrm or list");
  171. if (unlink(filename))
  172. ohshite(_("unable to delete control info file `%.250s'"), filename);
  173. debug(dbg_scripts, "removal_bulk info unlinked %s", filename);
  174. }
  175. static void
  176. removal_bulk_remove_files(struct pkginfo *pkg)
  177. {
  178. int before;
  179. struct reversefilelistiter rlistit;
  180. struct fileinlist *leftover;
  181. struct filenamenode *namenode;
  182. static struct varbuf fnvb;
  183. struct stat stab;
  184. pkg->status= stat_halfinstalled;
  185. modstatdb_note(pkg);
  186. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  187. reversefilelist_init(&rlistit,pkg->clientdata->files);
  188. leftover = NULL;
  189. while ((namenode= reversefilelist_next(&rlistit))) {
  190. struct filenamenode *usenode;
  191. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  192. namenode->name, namenode->flags);
  193. if (namenode->flags & fnnf_old_conff) {
  194. push_leftover(&leftover,namenode);
  195. continue;
  196. }
  197. usenode = namenodetouse(namenode, pkg);
  198. trig_file_activate(usenode, pkg);
  199. varbuf_reset(&fnvb);
  200. varbuf_add_str(&fnvb, instdir);
  201. varbuf_add_str(&fnvb, usenode->name);
  202. before= fnvb.used;
  203. varbuf_add_str(&fnvb, DPKGTEMPEXT);
  204. varbuf_end_str(&fnvb);
  205. debug(dbg_eachfiledetail, "removal_bulk cleaning temp `%s'", fnvb.buf);
  206. ensure_pathname_nonexisting(fnvb.buf);
  207. varbuf_trunc(&fnvb, before);
  208. varbuf_add_str(&fnvb, DPKGNEWEXT);
  209. varbuf_end_str(&fnvb);
  210. debug(dbg_eachfiledetail, "removal_bulk cleaning new `%s'", fnvb.buf);
  211. ensure_pathname_nonexisting(fnvb.buf);
  212. varbuf_trunc(&fnvb, before);
  213. varbuf_end_str(&fnvb);
  214. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  215. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  216. /* Only delete a directory or a link to one if we're the only
  217. * package which uses it. Other files should only be listed
  218. * in this package (but we don't check). */
  219. if (dir_has_conffiles(namenode, pkg)) {
  220. push_leftover(&leftover,namenode);
  221. continue;
  222. }
  223. if (dir_is_used_by_others(namenode, pkg))
  224. continue;
  225. }
  226. debug(dbg_eachfiledetail, "removal_bulk removing `%s'", fnvb.buf);
  227. if (!rmdir(fnvb.buf) || errno == ENOENT || errno == ELOOP) continue;
  228. if (errno == ENOTEMPTY || errno == EEXIST) {
  229. debug(dbg_eachfiledetail, "removal_bulk `%s' was not empty, will try again later",
  230. fnvb.buf);
  231. push_leftover(&leftover,namenode);
  232. continue;
  233. } else if (errno == EBUSY || errno == EPERM) {
  234. warning(_("while removing %.250s, unable to remove directory '%.250s': "
  235. "%s - directory may be a mount point?"),
  236. pkg->name, namenode->name, strerror(errno));
  237. push_leftover(&leftover,namenode);
  238. continue;
  239. } else if (errno == EINVAL && strcmp(usenode->name, "/.") == 0) {
  240. debug(dbg_eachfiledetail, "removal_bulk '%s' root directory, cannot remove",
  241. fnvb.buf);
  242. push_leftover(&leftover, namenode);
  243. continue;
  244. }
  245. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  246. debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);
  247. if (secure_unlink(fnvb.buf))
  248. ohshite(_("unable to securely remove '%.250s'"), fnvb.buf);
  249. }
  250. write_filelist_except(pkg,leftover,0);
  251. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  252. "remove", NULL);
  253. debug(dbg_general, "removal_bulk cleaning info directory");
  254. pkg_infodb_foreach(pkg, removal_bulk_remove_file);
  255. dir_sync_path(pkgadmindir());
  256. pkg->status= stat_configfiles;
  257. pkg->installed.essential = false;
  258. modstatdb_note(pkg);
  259. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  260. }
  261. static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) {
  262. struct reversefilelistiter rlistit;
  263. struct fileinlist *leftover;
  264. struct filenamenode *namenode;
  265. static struct varbuf fnvb;
  266. struct stat stab;
  267. /* We may have modified this previously. */
  268. ensure_packagefiles_available(pkg);
  269. modstatdb_note(pkg);
  270. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  271. reversefilelist_init(&rlistit,pkg->clientdata->files);
  272. leftover = NULL;
  273. while ((namenode= reversefilelist_next(&rlistit))) {
  274. struct filenamenode *usenode;
  275. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  276. namenode->name, namenode->flags);
  277. if (namenode->flags & fnnf_old_conff) {
  278. /* This can only happen if removal_bulk_remove_configfiles() got
  279. * interrupted half way. */
  280. debug(dbg_eachfiledetail, "removal_bulk expecting only left over dirs, "
  281. "ignoring conffile '%s'", namenode->name);
  282. continue;
  283. }
  284. usenode = namenodetouse(namenode, pkg);
  285. trig_file_activate(usenode, pkg);
  286. varbuf_reset(&fnvb);
  287. varbuf_add_str(&fnvb, instdir);
  288. varbuf_add_str(&fnvb, usenode->name);
  289. varbuf_end_str(&fnvb);
  290. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  291. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  292. /* Only delete a directory or a link to one if we're the only
  293. * package which uses it. Other files should only be listed
  294. * in this package (but we don't check). */
  295. if (dir_is_used_by_others(namenode, pkg))
  296. continue;
  297. }
  298. debug(dbg_eachfiledetail, "removal_bulk removing `%s'", fnvb.buf);
  299. if (!rmdir(fnvb.buf) || errno == ENOENT || errno == ELOOP) continue;
  300. if (errno == ENOTEMPTY || errno == EEXIST) {
  301. warning(_("while removing %.250s, directory '%.250s' not empty so not removed."),
  302. pkg->name, namenode->name);
  303. push_leftover(&leftover,namenode);
  304. continue;
  305. } else if (errno == EBUSY || errno == EPERM) {
  306. warning(_("while removing %.250s, unable to remove directory '%.250s': "
  307. "%s - directory may be a mount point?"),
  308. pkg->name, namenode->name, strerror(errno));
  309. push_leftover(&leftover,namenode);
  310. continue;
  311. } else if (errno == EINVAL && strcmp(usenode->name, "/.") == 0) {
  312. debug(dbg_eachfiledetail, "removal_bulk '%s' root directory, cannot remove",
  313. fnvb.buf);
  314. push_leftover(&leftover, namenode);
  315. continue;
  316. }
  317. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  318. if (lstat(fnvb.buf, &stab) == 0 && S_ISLNK(stab.st_mode)) {
  319. debug(dbg_eachfiledetail, "removal_bulk is a symlink to a directory");
  320. if (unlink(fnvb.buf))
  321. ohshite(_("cannot remove '%.250s'"), fnvb.buf);
  322. continue;
  323. }
  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. /* We may have modified this above. */
  346. ensure_packagefiles_available(pkg);
  347. /* We're about to remove the configuration, so remove the note
  348. * about which version it was ... */
  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. 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. varbuf_reset(&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;
  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. varbuf_reset(&removevb);
  393. varbuf_add_str(&removevb, fnvb.buf);
  394. varbuf_add_char(&removevb, '/');
  395. removevbbase= removevb.used;
  396. varbuf_end_str(&removevb);
  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. varbuf_trunc(&removevb, removevbbase);
  434. varbuf_add_str(&removevb, de->d_name);
  435. varbuf_end_str(&removevb);
  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. /* Remove the conffiles from the file list file. */
  445. write_filelist_except(pkg, pkg->clientdata->files, fnnf_old_conff);
  446. pkg->installed.conffiles = NULL;
  447. modstatdb_note(pkg);
  448. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  449. "purge", NULL);
  450. }
  451. /*
  452. * This is used both by deferred_remove() in this file, and at the end of
  453. * process_archive() in archives.c if it needs to finish removing a
  454. * conflicting package.
  455. */
  456. void removal_bulk(struct pkginfo *pkg) {
  457. bool foundpostrm;
  458. debug(dbg_general,"removal_bulk package %s",pkg->name);
  459. if (pkg->status == stat_halfinstalled || pkg->status == stat_unpacked) {
  460. removal_bulk_remove_files(pkg);
  461. }
  462. foundpostrm = pkg_infodb_has_file(pkg, POSTRMFILE);
  463. debug(dbg_general, "removal_bulk purging? foundpostrm=%d",foundpostrm);
  464. if (!foundpostrm && !pkg->installed.conffiles) {
  465. /* If there are no config files and no postrm script then we
  466. * go straight into ‘purge’. */
  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. /* I.e., either of the two branches above. */
  474. if (pkg->want == want_purge) {
  475. const char *filename;
  476. /* Retry empty directories, and warn on any leftovers that aren't. */
  477. removal_bulk_remove_leftover_dirs(pkg);
  478. filename = pkgadminfile(pkg, LISTFILE);
  479. debug(dbg_general, "removal_bulk purge done, removing list `%s'",
  480. filename);
  481. if (unlink(filename) && errno != ENOENT)
  482. ohshite(_("cannot remove old files list"));
  483. filename = pkgadminfile(pkg, POSTRMFILE);
  484. debug(dbg_general, "removal_bulk purge done, removing postrm `%s'",
  485. filename);
  486. if (unlink(filename) && errno != ENOENT)
  487. ohshite(_("can't remove old postrm script"));
  488. pkg->status= stat_notinstalled;
  489. pkg->want = want_unknown;
  490. /* This will mess up reverse links, but if we follow them
  491. * we won't go back because pkg->status is stat_notinstalled. */
  492. pkgbin_blank(&pkg->installed);
  493. }
  494. pkg->eflag = eflag_ok;
  495. modstatdb_note(pkg);
  496. debug(dbg_general, "removal done");
  497. }