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 <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/options.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_pkg(namenode, pkg, leftover)) {
  224. push_leftover(&leftover, namenode);
  225. continue;
  226. }
  227. if (dir_is_used_by_others(namenode, pkg))
  228. continue;
  229. }
  230. debug(dbg_eachfiledetail, "removal_bulk removing `%s'", fnvb.buf);
  231. if (!rmdir(fnvb.buf) || errno == ENOENT || errno == ELOOP) continue;
  232. if (errno == ENOTEMPTY || errno == EEXIST) {
  233. debug(dbg_eachfiledetail, "removal_bulk `%s' was not empty, will try again later",
  234. fnvb.buf);
  235. push_leftover(&leftover,namenode);
  236. continue;
  237. } else if (errno == EBUSY || errno == EPERM) {
  238. warning(_("while removing %.250s, unable to remove directory '%.250s': "
  239. "%s - directory may be a mount point?"),
  240. pkg->name, namenode->name, strerror(errno));
  241. push_leftover(&leftover,namenode);
  242. continue;
  243. } else if (errno == EINVAL && strcmp(usenode->name, "/.") == 0) {
  244. debug(dbg_eachfiledetail, "removal_bulk '%s' root directory, cannot remove",
  245. fnvb.buf);
  246. push_leftover(&leftover, namenode);
  247. continue;
  248. }
  249. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  250. debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);
  251. if (secure_unlink(fnvb.buf))
  252. ohshite(_("unable to securely remove '%.250s'"), fnvb.buf);
  253. }
  254. write_filelist_except(pkg,leftover,0);
  255. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  256. "remove", NULL);
  257. trig_parse_ci(pkgadminfile(pkg, TRIGGERSCIFILE),
  258. trig_cicb_interest_delete, NULL, pkg);
  259. trig_file_interests_save();
  260. debug(dbg_general, "removal_bulk cleaning info directory");
  261. pkg_infodb_foreach(pkg, removal_bulk_remove_file);
  262. dir_sync_path(pkgadmindir());
  263. pkg->status= stat_configfiles;
  264. pkg->installed.essential = false;
  265. modstatdb_note(pkg);
  266. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  267. }
  268. static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) {
  269. struct reversefilelistiter rlistit;
  270. struct fileinlist *leftover;
  271. struct filenamenode *namenode;
  272. static struct varbuf fnvb;
  273. struct stat stab;
  274. /* We may have modified this previously. */
  275. ensure_packagefiles_available(pkg);
  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. /* This can only happen if removal_bulk_remove_configfiles() got
  286. * interrupted half way. */
  287. debug(dbg_eachfiledetail, "removal_bulk expecting only left over dirs, "
  288. "ignoring conffile '%s'", namenode->name);
  289. continue;
  290. }
  291. usenode = namenodetouse(namenode, pkg);
  292. trig_file_activate(usenode, pkg);
  293. varbuf_reset(&fnvb);
  294. varbuf_add_str(&fnvb, instdir);
  295. varbuf_add_str(&fnvb, usenode->name);
  296. varbuf_end_str(&fnvb);
  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. if (dir_is_used_by_pkg(namenode, pkg, leftover)) {
  303. push_leftover(&leftover, namenode);
  304. continue;
  305. }
  306. if (dir_is_used_by_others(namenode, pkg))
  307. 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. } else if (errno == EINVAL && strcmp(usenode->name, "/.") == 0) {
  323. debug(dbg_eachfiledetail, "removal_bulk '%s' root directory, cannot remove",
  324. fnvb.buf);
  325. push_leftover(&leftover, namenode);
  326. continue;
  327. }
  328. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  329. if (lstat(fnvb.buf, &stab) == 0 && S_ISLNK(stab.st_mode)) {
  330. debug(dbg_eachfiledetail, "removal_bulk is a symlink to a directory");
  331. if (unlink(fnvb.buf))
  332. ohshite(_("cannot remove '%.250s'"), fnvb.buf);
  333. continue;
  334. }
  335. push_leftover(&leftover,namenode);
  336. continue;
  337. }
  338. write_filelist_except(pkg,leftover,0);
  339. modstatdb_note(pkg);
  340. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  341. }
  342. static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
  343. static const char *const removeconffexts[] = { REMOVECONFFEXTS, NULL };
  344. int r, removevbbase;
  345. int conffnameused, conffbasenamelen;
  346. char *conffbasename;
  347. struct conffile *conff, **lconffp;
  348. struct fileinlist *searchfile;
  349. DIR *dsd;
  350. struct dirent *de;
  351. char *p;
  352. const char *const *ext;
  353. printf(_("Purging configuration files for %s ...\n"),pkg->name);
  354. log_action("purge", pkg);
  355. trig_activate_packageprocessing(pkg);
  356. /* We may have modified this above. */
  357. ensure_packagefiles_available(pkg);
  358. /* We're about to remove the configuration, so remove the note
  359. * about which version it was ... */
  360. blankversion(&pkg->configversion);
  361. modstatdb_note(pkg);
  362. /* Remove from our list any conffiles that aren't ours any more or
  363. * are involved in diversions, except if we are the package doing the
  364. * diverting. */
  365. for (lconffp = &pkg->installed.conffiles; (conff = *lconffp) != NULL; ) {
  366. for (searchfile= pkg->clientdata->files;
  367. searchfile && strcmp(searchfile->namenode->name,conff->name);
  368. searchfile= searchfile->next);
  369. if (!searchfile) {
  370. debug(dbg_conff,"removal_bulk conffile not ours any more `%s'",conff->name);
  371. *lconffp= conff->next;
  372. } else if (searchfile->namenode->divert &&
  373. (searchfile->namenode->divert->camefrom ||
  374. (searchfile->namenode->divert->useinstead &&
  375. searchfile->namenode->divert->pkg != pkg))) {
  376. debug(dbg_conff, "removal_bulk conffile '%s' ignored due to diversion",
  377. conff->name);
  378. *lconffp= conff->next;
  379. } else {
  380. debug(dbg_conffdetail,"removal_bulk set to new conffile `%s'",conff->name);
  381. conff->hash = NEWCONFFILEFLAG;
  382. lconffp= &conff->next;
  383. }
  384. }
  385. modstatdb_note(pkg);
  386. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  387. static struct varbuf fnvb, removevb;
  388. if (conff->obsolete) {
  389. debug(dbg_conffdetail, "removal_bulk conffile obsolete %s",
  390. conff->name);
  391. }
  392. varbuf_reset(&fnvb);
  393. r= conffderef(pkg, &fnvb, conff->name);
  394. debug(dbg_conffdetail, "removal_bulk conffile `%s' (= `%s')",
  395. conff->name, r == -1 ? "<r==-1>" : fnvb.buf);
  396. if (r == -1) continue;
  397. conffnameused = fnvb.used;
  398. if (unlink(fnvb.buf) && errno != ENOENT && errno != ENOTDIR)
  399. ohshite(_("cannot remove old config file `%.250s' (= `%.250s')"),
  400. conff->name, fnvb.buf);
  401. p= strrchr(fnvb.buf,'/'); if (!p) continue;
  402. *p = '\0';
  403. varbuf_reset(&removevb);
  404. varbuf_add_str(&removevb, fnvb.buf);
  405. varbuf_add_char(&removevb, '/');
  406. removevbbase= removevb.used;
  407. varbuf_end_str(&removevb);
  408. dsd= opendir(removevb.buf);
  409. if (!dsd) {
  410. int e=errno;
  411. debug(dbg_conffdetail, "removal_bulk conffile no dsd %s %s",
  412. fnvb.buf, strerror(e)); errno= e;
  413. if (errno == ENOENT || errno == ENOTDIR) continue;
  414. ohshite(_("cannot read config file dir `%.250s' (from `%.250s')"),
  415. fnvb.buf, conff->name);
  416. }
  417. debug(dbg_conffdetail, "removal_bulk conffile cleaning dsd %s", fnvb.buf);
  418. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  419. *p= '/';
  420. conffbasenamelen= strlen(++p);
  421. conffbasename= fnvb.buf+conffnameused-conffbasenamelen;
  422. while ((de = readdir(dsd)) != NULL) {
  423. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry=`%s'"
  424. " conffbasename=`%s' conffnameused=%d conffbasenamelen=%d",
  425. de->d_name, conffbasename, conffnameused, conffbasenamelen);
  426. if (!strncmp(de->d_name,conffbasename,conffbasenamelen)) {
  427. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts right");
  428. for (ext= removeconffexts; *ext; ext++)
  429. if (!strcmp(*ext,de->d_name+conffbasenamelen)) goto yes_remove;
  430. p= de->d_name+conffbasenamelen;
  431. if (*p++ == '~') {
  432. while (*p && cisdigit(*p)) p++;
  433. if (*p == '~' && !*++p) goto yes_remove;
  434. }
  435. }
  436. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts wrong");
  437. if (de->d_name[0] == '#' &&
  438. !strncmp(de->d_name+1,conffbasename,conffbasenamelen) &&
  439. !strcmp(de->d_name+1+conffbasenamelen,"#"))
  440. goto yes_remove;
  441. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry not it");
  442. continue;
  443. yes_remove:
  444. varbuf_trunc(&removevb, removevbbase);
  445. varbuf_add_str(&removevb, de->d_name);
  446. varbuf_end_str(&removevb);
  447. debug(dbg_conffdetail, "removal_bulk conffile dsd entry removing `%s'",
  448. removevb.buf);
  449. if (unlink(removevb.buf) && errno != ENOENT && errno != ENOTDIR)
  450. ohshite(_("cannot remove old backup config file `%.250s' (of `%.250s')"),
  451. removevb.buf, conff->name);
  452. }
  453. pop_cleanup(ehflag_normaltidy); /* closedir */
  454. }
  455. /* Remove the conffiles from the file list file. */
  456. write_filelist_except(pkg, pkg->clientdata->files, fnnf_old_conff);
  457. pkg->installed.conffiles = NULL;
  458. modstatdb_note(pkg);
  459. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  460. "purge", NULL);
  461. }
  462. /*
  463. * This is used both by deferred_remove() in this file, and at the end of
  464. * process_archive() in archives.c if it needs to finish removing a
  465. * conflicting package.
  466. */
  467. void removal_bulk(struct pkginfo *pkg) {
  468. bool foundpostrm;
  469. debug(dbg_general,"removal_bulk package %s",pkg->name);
  470. if (pkg->status == stat_halfinstalled || pkg->status == stat_unpacked) {
  471. removal_bulk_remove_files(pkg);
  472. }
  473. foundpostrm = pkg_infodb_has_file(pkg, POSTRMFILE);
  474. debug(dbg_general, "removal_bulk purging? foundpostrm=%d",foundpostrm);
  475. if (!foundpostrm && !pkg->installed.conffiles) {
  476. /* If there are no config files and no postrm script then we
  477. * go straight into ‘purge’. */
  478. debug(dbg_general, "removal_bulk no postrm, no conffiles, purging");
  479. pkg->want= want_purge;
  480. blankversion(&pkg->configversion);
  481. } else if (pkg->want == want_purge) {
  482. removal_bulk_remove_configfiles(pkg);
  483. }
  484. /* I.e., either of the two branches above. */
  485. if (pkg->want == want_purge) {
  486. const char *filename;
  487. /* Retry empty directories, and warn on any leftovers that aren't. */
  488. removal_bulk_remove_leftover_dirs(pkg);
  489. filename = pkgadminfile(pkg, LISTFILE);
  490. debug(dbg_general, "removal_bulk purge done, removing list `%s'",
  491. filename);
  492. if (unlink(filename) && errno != ENOENT)
  493. ohshite(_("cannot remove old files list"));
  494. filename = pkgadminfile(pkg, POSTRMFILE);
  495. debug(dbg_general, "removal_bulk purge done, removing postrm `%s'",
  496. filename);
  497. if (unlink(filename) && errno != ENOENT)
  498. ohshite(_("can't remove old postrm script"));
  499. pkg->status= stat_notinstalled;
  500. pkg->want = want_unknown;
  501. /* This will mess up reverse links, but if we follow them
  502. * we won't go back because pkg->status is stat_notinstalled. */
  503. pkgbin_blank(&pkg->installed);
  504. }
  505. pkg->eflag = eflag_ok;
  506. modstatdb_note(pkg);
  507. debug(dbg_general, "removal done");
  508. }