remove.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /* Change: separate removal_bulk handling of halfinstalled or unpacked pkgs
  2. * (ie, remove the real files in the .deb) into its own function.
  3. * Note that "installed" state is converted to unpacked by
  4. * deferred_remove() or halfinstalled by process_archive())
  5. *
  6. * Change: separate purging of configfiles and running of postrm to its
  7. * own function.
  8. *
  9. * Change: retry removing directories after postrm purge is finished, to
  10. * handle directories that had conffiles or config files and so
  11. * forth in them. also only warn about non-empty directories at
  12. * that point.
  13. */
  14. /*
  15. * dpkg - main program for package management
  16. * remove.c - functionality for removing packages
  17. *
  18. * Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  19. *
  20. * This is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2,
  23. * or (at your option) any later version.
  24. *
  25. * This is distributed in the hope that it will be useful, but
  26. * WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public
  31. * License along with dpkg; if not, write to the Free Software
  32. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. */
  34. #include <config.h>
  35. #include <errno.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <unistd.h>
  40. #include <fcntl.h>
  41. #include <sys/stat.h>
  42. #include <sys/types.h>
  43. #include <dirent.h>
  44. #include <ctype.h>
  45. #include <unistd.h>
  46. #include <string.h>
  47. #include <assert.h>
  48. #include <dpkg.h>
  49. #include <dpkg-db.h>
  50. #include <myopt.h>
  51. #include "filesdb.h"
  52. #include "main.h"
  53. static void checkforremoval(struct pkginfo *pkgtoremove,
  54. struct pkginfo *pkgdepcheck, /* may be virtual pkg */
  55. int *rokp, struct varbuf *raemsgs) {
  56. struct deppossi *possi;
  57. struct pkginfo *depender;
  58. int before, ok;
  59. for (possi= pkgdepcheck->installed.depended; possi; possi= possi->nextrev) {
  60. if (possi->up->type != dep_depends && possi->up->type != dep_predepends) continue;
  61. depender= possi->up->up;
  62. debug(dbg_depcon,"checking depending package `%s'",depender->name);
  63. if (depender->status != stat_installed) continue;
  64. if (ignore_depends(depender)) {
  65. debug(dbg_depcon,"ignoring depending package `%s'\n",depender->name);
  66. continue;
  67. }
  68. if (dependtry > 1) { if (findbreakcycle(pkgtoremove,0)) sincenothing= 0; }
  69. before= raemsgs->used;
  70. ok= dependencies_ok(depender,pkgtoremove,raemsgs);
  71. if (ok == 0 && depender->clientdata->istobe == itb_remove) ok= 1;
  72. if (ok == 1) raemsgs->used= before; /* Don't burble about reasons for deferral */
  73. if (ok < *rokp) *rokp= ok;
  74. }
  75. }
  76. void deferred_remove(struct pkginfo *pkg) {
  77. struct varbuf raemsgs;
  78. int rok;
  79. struct dependency *dep;
  80. debug(dbg_general,"deferred_remove package %s",pkg->name);
  81. if (pkg->status == stat_notinstalled) {
  82. fprintf(stderr,
  83. _("dpkg - warning: ignoring request to remove %.250s which isn't installed.\n"),
  84. pkg->name);
  85. pkg->clientdata->istobe= itb_normal;
  86. return;
  87. } else if (!f_pending &&
  88. pkg->status == stat_configfiles &&
  89. cipaction->arg != act_purge) {
  90. fprintf(stderr,
  91. _("dpkg - warning: ignoring request to remove %.250s, only the config\n"
  92. " files of which are on the system. Use --purge to remove them too.\n"),
  93. pkg->name);
  94. pkg->clientdata->istobe= itb_normal;
  95. return;
  96. }
  97. assert(pkg->installed.valid);
  98. if (pkg->installed.essential && pkg->status != stat_configfiles)
  99. forcibleerr(fc_removeessential, _("This is an essential package -"
  100. " it should not be removed."));
  101. if (!f_pending)
  102. pkg->want= (cipaction->arg == act_purge) ? want_purge : want_deinstall;
  103. if (!f_noact) modstatdb_note(pkg);
  104. debug(dbg_general,"checking dependencies for remove `%s'",pkg->name);
  105. varbufinit(&raemsgs);
  106. rok= 2;
  107. checkforremoval(pkg,pkg,&rok,&raemsgs);
  108. for (dep= pkg->installed.depends; dep; dep= dep->next) {
  109. if (dep->type != dep_provides) continue;
  110. debug(dbg_depcon,"checking virtual package `%s'",dep->list->ed->name);
  111. checkforremoval(pkg,dep->list->ed,&rok,&raemsgs);
  112. }
  113. if (rok == 1) {
  114. varbuffree(&raemsgs);
  115. pkg->clientdata->istobe= itb_remove;
  116. add_to_queue(pkg);
  117. return;
  118. } else if (rok == 0) {
  119. sincenothing= 0;
  120. varbufaddc(&raemsgs,0);
  121. fprintf(stderr,
  122. _("dpkg: dependency problems prevent removal of %s:\n%s"),
  123. pkg->name, raemsgs.buf);
  124. ohshit(_("dependency problems - not removing"));
  125. } else if (raemsgs.used) {
  126. varbufaddc(&raemsgs,0);
  127. fprintf(stderr,
  128. _("dpkg: %s: dependency problems, but removing anyway as you request:\n%s"),
  129. pkg->name, raemsgs.buf);
  130. }
  131. varbuffree(&raemsgs);
  132. sincenothing= 0;
  133. if (pkg->eflag & eflagf_reinstreq)
  134. forcibleerr(fc_removereinstreq,
  135. _("Package is in a very bad inconsistent state - you should\n"
  136. " reinstall it before attempting a removal."));
  137. ensure_allinstfiles_available();
  138. filesdbinit();
  139. if (f_noact) {
  140. printf(_("Would remove or purge %s ...\n"),pkg->name);
  141. pkg->status= stat_notinstalled;
  142. pkg->clientdata->istobe= itb_normal;
  143. return;
  144. }
  145. oldconffsetflags(pkg->installed.conffiles);
  146. printf(_("Removing %s ...\n"),pkg->name);
  147. if (pkg->status == stat_halfconfigured || pkg->status == stat_installed) {
  148. if (pkg->status == stat_installed || pkg->status == stat_halfconfigured) {
  149. pkg->status= stat_halfconfigured;
  150. modstatdb_note(pkg);
  151. push_cleanup(cu_prermremove,~ehflag_normaltidy, 0,0, 1,(void*)pkg);
  152. maintainer_script_installed(pkg, PRERMFILE, "pre-removal",
  153. "remove", (char*)0);
  154. }
  155. pkg->status= stat_unpacked; /* Will turn into halfinstalled soon ... */
  156. }
  157. removal_bulk(pkg);
  158. }
  159. static void push_leftover(struct fileinlist **leftoverp,
  160. struct filenamenode *namenode) {
  161. struct fileinlist *newentry;
  162. newentry= nfmalloc(sizeof(struct fileinlist));
  163. newentry->next= *leftoverp;
  164. newentry->namenode= namenode;
  165. *leftoverp= newentry;
  166. }
  167. static void removal_bulk_remove_files(
  168. struct pkginfo *pkg,
  169. int *out_foundpostrm)
  170. {
  171. int before;
  172. int infodirbaseused;
  173. struct reversefilelistiter rlistit;
  174. struct fileinlist *leftover;
  175. struct filenamenode *namenode;
  176. static struct varbuf fnvb;
  177. DIR *dsd;
  178. struct dirent *de;
  179. struct stat stab;
  180. pkg->status= stat_halfinstalled;
  181. modstatdb_note(pkg);
  182. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  183. reversefilelist_init(&rlistit,pkg->clientdata->files);
  184. leftover= 0;
  185. while ((namenode= reversefilelist_next(&rlistit))) {
  186. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  187. namenode->name, namenode->flags);
  188. if (namenode->flags & fnnf_old_conff) {
  189. push_leftover(&leftover,namenode);
  190. continue;
  191. }
  192. varbufreset(&fnvb);
  193. varbufaddstr(&fnvb,instdir);
  194. varbufaddstr(&fnvb,namenodetouse(namenode,pkg)->name);
  195. before= fnvb.used;
  196. varbufaddstr(&fnvb,DPKGTEMPEXT);
  197. varbufaddc(&fnvb,0);
  198. debug(dbg_eachfiledetail, "removal_bulk cleaning temp `%s'", fnvb.buf);
  199. ensure_pathname_nonexisting(fnvb.buf);
  200. fnvb.used= before;
  201. varbufaddstr(&fnvb,DPKGNEWEXT);
  202. varbufaddc(&fnvb,0);
  203. debug(dbg_eachfiledetail, "removal_bulk cleaning new `%s'", fnvb.buf);
  204. ensure_pathname_nonexisting(fnvb.buf);
  205. fnvb.used= before;
  206. varbufaddc(&fnvb,0);
  207. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  208. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  209. /* Only delete a directory or a link to one if we're the only
  210. * package which uses it. Other files should only be listed
  211. * in this package (but we don't check).
  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) {
  218. push_leftover(&leftover,namenode);
  219. continue;
  220. } else if (errno == EBUSY || errno == EPERM) {
  221. fprintf(stderr, _("dpkg - warning: while removing %.250s,"
  222. " unable to remove directory `%.250s':"
  223. " %s - directory may be a mount point ?\n"),
  224. pkg->name, namenode->name, strerror(errno));
  225. push_leftover(&leftover,namenode);
  226. continue;
  227. }
  228. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  229. debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);
  230. {
  231. /*
  232. * If file to remove is a device or s[gu]id, change its mode
  233. * so that a malicious user cannot use it even if it's linked
  234. * to another file
  235. */
  236. struct stat stat_buf;
  237. if (stat(fnvb.buf,&stat_buf)==0) {
  238. if (S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode)) {
  239. chmod(fnvb.buf,0);
  240. }
  241. if (stat_buf.st_mode & (S_ISUID|S_ISGID)) {
  242. chmod(fnvb.buf,stat_buf.st_mode & ~(S_ISUID|S_ISGID));
  243. }
  244. }
  245. }
  246. if (unlink(fnvb.buf)) ohshite(_("cannot remove file `%.250s'"),fnvb.buf);
  247. }
  248. write_filelist_except(pkg,leftover,0);
  249. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  250. "remove", (char*)0);
  251. varbufreset(&fnvb);
  252. varbufaddstr(&fnvb,admindir);
  253. varbufaddstr(&fnvb,"/" INFODIR);
  254. infodirbaseused= fnvb.used;
  255. varbufaddc(&fnvb,0);
  256. dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
  257. push_cleanup(cu_closedir,~0, 0,0, 1,(void*)dsd);
  258. *out_foundpostrm= 0;
  259. debug(dbg_general, "removal_bulk cleaning info directory");
  260. while ((de= readdir(dsd)) != 0) {
  261. char *p;
  262. debug(dbg_veryverbose, "removal_bulk info file `%s'", de->d_name);
  263. if (de->d_name[0] == '.') continue;
  264. p= strrchr(de->d_name,'.'); if (!p) continue;
  265. if (strlen(pkg->name) != (size_t)(p-de->d_name) ||
  266. strncmp(de->d_name,pkg->name,p-de->d_name)) continue;
  267. debug(dbg_stupidlyverbose, "removal_bulk info this pkg");
  268. /* We need the postrm and list files for --purge. */
  269. if (!strcmp(p+1,LISTFILE)) continue;
  270. if (!strcmp(p+1,POSTRMFILE)) { *out_foundpostrm=1; continue; }
  271. debug(dbg_stupidlyverbose, "removal_bulk info not postrm or list");
  272. fnvb.used= infodirbaseused;
  273. varbufaddstr(&fnvb,de->d_name);
  274. varbufaddc(&fnvb,0);
  275. if (unlink(fnvb.buf))
  276. ohshite(_("unable to delete control info file `%.250s'"),fnvb.buf);
  277. debug(dbg_scripts, "removal_bulk info unlinked %s",fnvb.buf);
  278. }
  279. pop_cleanup(ehflag_normaltidy); /* closedir */
  280. pkg->status= stat_configfiles;
  281. pkg->installed.essential= 0;
  282. modstatdb_note(pkg);
  283. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  284. }
  285. static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) {
  286. struct reversefilelistiter rlistit;
  287. struct fileinlist *leftover;
  288. struct filenamenode *namenode;
  289. static struct varbuf fnvb;
  290. struct stat stab;
  291. modstatdb_note(pkg);
  292. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  293. reversefilelist_init(&rlistit,pkg->clientdata->files);
  294. leftover= 0;
  295. while ((namenode= reversefilelist_next(&rlistit))) {
  296. debug(dbg_eachfile, "removal_bulk `%s' flags=%o",
  297. namenode->name, namenode->flags);
  298. if (namenode->flags & fnnf_old_conff) {
  299. push_leftover(&leftover,namenode);
  300. continue;
  301. }
  302. varbufreset(&fnvb);
  303. varbufaddstr(&fnvb,instdir);
  304. varbufaddstr(&fnvb,namenodetouse(namenode,pkg)->name);
  305. if (!stat(fnvb.buf,&stab) && S_ISDIR(stab.st_mode)) {
  306. debug(dbg_eachfiledetail, "removal_bulk is a directory");
  307. /* Only delete a directory or a link to one if we're the only
  308. * package which uses it. Other files should only be listed
  309. * in this package (but we don't check).
  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) {
  316. fprintf(stderr,
  317. _("dpkg - warning: while removing %.250s, directory `%.250s' not empty "
  318. "so not removed.\n"),
  319. pkg->name, namenode->name);
  320. push_leftover(&leftover,namenode);
  321. continue;
  322. } else if (errno == EBUSY || errno == EPERM) {
  323. fprintf(stderr, _("dpkg - warning: while removing %.250s,"
  324. " unable to remove directory `%.250s':"
  325. " %s - directory may be a mount point ?\n"),
  326. pkg->name, namenode->name, strerror(errno));
  327. push_leftover(&leftover,namenode);
  328. continue;
  329. }
  330. if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
  331. push_leftover(&leftover,namenode);
  332. continue;
  333. }
  334. write_filelist_except(pkg,leftover,0);
  335. modstatdb_note(pkg);
  336. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  337. }
  338. static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
  339. static const char *const removeconffexts[]= { REMOVECONFFEXTS, 0 };
  340. int r, removevbbase;
  341. int conffnameused, conffbasenamelen;
  342. char *conffbasename;
  343. struct conffile *conff, **lconffp;
  344. struct fileinlist *searchfile;
  345. DIR *dsd;
  346. struct dirent *de;
  347. char *p;
  348. const char *const *ext;
  349. printf(_("Purging configuration files for %s ...\n"),pkg->name);
  350. ensure_packagefiles_available(pkg); /* We may have modified this above. */
  351. /* We're about to remove the configuration, so remove the note
  352. * about which version it was ...
  353. */
  354. blankversion(&pkg->configversion);
  355. modstatdb_note(pkg);
  356. /* Remove from our list any conffiles that aren't ours any more or
  357. * are involved in diversions, except if we are the package doing the
  358. * diverting.
  359. */
  360. for (lconffp= &pkg->installed.conffiles;
  361. (conff= *lconffp) != 0;
  362. lconffp= &conff->next) {
  363. for (searchfile= pkg->clientdata->files;
  364. searchfile && strcmp(searchfile->namenode->name,conff->name);
  365. searchfile= searchfile->next);
  366. if (!searchfile) {
  367. debug(dbg_conff,"removal_bulk conffile not ours any more `%s'",conff->name);
  368. *lconffp= conff->next;
  369. } else if (searchfile->namenode->divert &&
  370. (searchfile->namenode->divert->camefrom ||
  371. (searchfile->namenode->divert->useinstead &&
  372. searchfile->namenode->divert->pkg != pkg))) {
  373. debug(dbg_conff,"removal_bulk conffile `%s' ignored due to diversion\n",
  374. conff->name);
  375. *lconffp= conff->next;
  376. } else {
  377. debug(dbg_conffdetail,"removal_bulk set to new conffile `%s'",conff->name);
  378. conff->hash= NEWCONFFILEFLAG; /* yes, cast away const */
  379. }
  380. }
  381. modstatdb_note(pkg);
  382. for (conff= pkg->installed.conffiles; conff; conff= conff->next) {
  383. static struct varbuf fnvb, removevb;
  384. varbufreset(&fnvb);
  385. r= conffderef(pkg, &fnvb, conff->name);
  386. debug(dbg_conffdetail, "removal_bulk conffile `%s' (= `%s')",
  387. conff->name, r == -1 ? "<r==-1>" : fnvb.buf);
  388. if (r == -1) continue;
  389. conffnameused= fnvb.used-1;
  390. if (unlink(fnvb.buf) && errno != ENOENT && errno != ENOTDIR)
  391. ohshite(_("cannot remove old config file `%.250s' (= `%.250s')"),
  392. conff->name, fnvb.buf);
  393. p= strrchr(fnvb.buf,'/'); if (!p) continue;
  394. *p= 0;
  395. varbufreset(&removevb);
  396. varbufaddstr(&removevb,fnvb.buf);
  397. varbufaddc(&removevb,'/');
  398. removevbbase= removevb.used;
  399. varbufaddc(&removevb,0);
  400. dsd= opendir(removevb.buf);
  401. if (!dsd) {
  402. int e=errno;
  403. debug(dbg_conffdetail, "removal_bulk conffile no dsd %s %s",
  404. fnvb.buf, strerror(e)); errno= e;
  405. if (errno == ENOENT || errno == ENOTDIR) continue;
  406. ohshite(_("cannot read config file dir `%.250s' (from `%.250s')"),
  407. fnvb.buf, conff->name);
  408. }
  409. debug(dbg_conffdetail, "removal_bulk conffile cleaning dsd %s", fnvb.buf);
  410. push_cleanup(cu_closedir,~0, 0,0, 1,(void*)dsd);
  411. *p= '/';
  412. conffbasenamelen= strlen(++p);
  413. conffbasename= fnvb.buf+conffnameused-conffbasenamelen;
  414. while ((de= readdir(dsd)) != 0) {
  415. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry=`%s'"
  416. " conffbasename=`%s' conffnameused=%d conffbasenamelen=%d",
  417. de->d_name, conffbasename, conffnameused, conffbasenamelen);
  418. if (!strncmp(de->d_name,conffbasename,conffbasenamelen)) {
  419. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts right");
  420. for (ext= removeconffexts; *ext; ext++)
  421. if (!strcmp(*ext,de->d_name+conffbasenamelen)) goto yes_remove;
  422. p= de->d_name+conffbasenamelen;
  423. if (*p++ == '~') {
  424. while (*p && cisdigit(*p)) p++;
  425. if (*p == '~' && !*++p) goto yes_remove;
  426. }
  427. }
  428. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry starts wrong");
  429. if (de->d_name[0] == '#' &&
  430. !strncmp(de->d_name+1,conffbasename,conffbasenamelen) &&
  431. !strcmp(de->d_name+1+conffbasenamelen,"#"))
  432. goto yes_remove;
  433. debug(dbg_stupidlyverbose, "removal_bulk conffile dsd entry not it");
  434. continue;
  435. yes_remove:
  436. removevb.used= removevbbase;
  437. varbufaddstr(&removevb,de->d_name); varbufaddc(&removevb,0);
  438. debug(dbg_conffdetail, "removal_bulk conffile dsd entry removing `%s'",
  439. removevb.buf);
  440. if (unlink(removevb.buf) && errno != ENOENT && errno != ENOTDIR)
  441. ohshite(_("cannot remove old backup config file `%.250s' (of `%.250s')"),
  442. removevb.buf, conff->name);
  443. }
  444. pop_cleanup(ehflag_normaltidy); /* closedir */
  445. }
  446. pkg->installed.conffiles= 0;
  447. modstatdb_note(pkg);
  448. maintainer_script_installed(pkg, POSTRMFILE, "post-removal",
  449. "purge", (char*)0);
  450. }
  451. void removal_bulk(struct pkginfo *pkg) {
  452. /* This is used both by deferred_remove in this file, and at
  453. * the end of process_archive in archives.c if it needs to finish
  454. * removing a conflicting package.
  455. */
  456. int pkgnameused;
  457. int foundpostrm= 0;
  458. const char *postrmfilename;
  459. debug(dbg_general,"removal_bulk package %s",pkg->name);
  460. if (pkg->status == stat_halfinstalled || pkg->status == stat_unpacked) {
  461. removal_bulk_remove_files(pkg, &foundpostrm);
  462. } else {
  463. struct stat stab;
  464. postrmfilename= pkgadminfile(pkg,POSTRMFILE);
  465. if (!lstat(postrmfilename,&stab)) foundpostrm= 1;
  466. else if (errno == ENOENT) foundpostrm= 0;
  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. } else if (pkg->want == want_purge) {
  477. removal_bulk_remove_configfiles(pkg);
  478. }
  479. if (pkg->want == want_purge) {
  480. /* ie, either of the two branches above. */
  481. static struct varbuf fnvb;
  482. /* retry empty directories, and warn on any leftovers that aren't */
  483. removal_bulk_remove_leftover_dirs(pkg);
  484. varbufreset(&fnvb);
  485. varbufaddstr(&fnvb,admindir);
  486. varbufaddstr(&fnvb,"/" INFODIR);
  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. /* This will mess up reverse links, but if we follow them
  500. * we won't go back because pkg->status is stat_notinstalled.
  501. */
  502. pkg->installed.depends= 0;
  503. pkg->installed.essential= 0;
  504. pkg->installed.description= pkg->installed.maintainer= 0;
  505. pkg->installed.source= pkg->installed.installedsize= 0;
  506. blankversion(&pkg->installed.version);
  507. pkg->installed.arbs= 0;
  508. }
  509. pkg->eflag= eflagv_ok;
  510. modstatdb_note(pkg);
  511. debug(dbg_general, "removal done");
  512. }