remove.c 20 KB

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