processarc.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /*
  2. * dpkg - main program for package management
  3. * processarc.c - the huge function process_archive
  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
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * 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
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <dpkg-i18n.h>
  24. #include <errno.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <unistd.h>
  29. #include <utime.h>
  30. #include <assert.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33. #include <dirent.h>
  34. #include <fcntl.h>
  35. #include <sys/stat.h>
  36. #include <sys/types.h>
  37. #include <sys/wait.h>
  38. #include <dpkg.h>
  39. #include <dpkg-db.h>
  40. #include <tarfn.h>
  41. #include <myopt.h>
  42. #include "filesdb.h"
  43. #include "main.h"
  44. #include "archives.h"
  45. void process_archive(const char *filename) {
  46. static const struct TarFunctions tf = {
  47. tarfileread,
  48. tarobject, tarobject, tarobject, tarobject, tarobject
  49. };
  50. /* These need to be static so that we can pass their addresses to
  51. * push_cleanup as arguments to the cu_xxx routines; if an error occurs
  52. * we unwind the stack before processing the cleanup list, and these
  53. * variables had better still exist ...
  54. */
  55. static int p1[2];
  56. static char cidirtmpnambuf[L_tmpnam+100];
  57. static char *cidirbuf = NULL, *reasmbuf = NULL;
  58. static struct fileinlist *newconffiles, *newfileslist;
  59. static enum pkgstatus oldversionstatus;
  60. static struct varbuf infofnvb, fnvb, depprobwhy;
  61. static struct tarcontext tc;
  62. int c1, r, admindirlen, i, infodirlen, infodirbaseused, status;
  63. struct pkgiterator *it;
  64. struct pkginfo *pkg, *otherpkg, *divpkg;
  65. char *cidir, *cidirrest, *p;
  66. char *pfilenamebuf, conffilenamebuf[MAXCONFFILENAME];
  67. char *psize;
  68. const char *pfilename, *newinfofilename, *failed;
  69. struct fileinlist *newconff, **newconffileslastp;
  70. struct fileinlist *cfile;
  71. struct reversefilelistiter rlistit;
  72. struct conffile *searchconff, **iconffileslastp, *newiconff;
  73. struct filepackages *packageslump;
  74. struct dependency *dsearch, *newdeplist, **newdeplistlastp;
  75. struct dependency *newdep, *dep, *providecheck;
  76. struct deppossi *psearch, **newpossilastp, *possi, *newpossi, *pdep;
  77. FILE *conff;
  78. DIR *dsd;
  79. struct filenamenode *namenode;
  80. struct dirent *de;
  81. struct stat stab, oldfs;
  82. struct pkg_deconf_list *deconpil, *deconpiltemp;
  83. cleanup_pkg_failed= cleanup_conflictor_failed= 0;
  84. admindirlen= strlen(admindir);
  85. for (pfilename= filename ; pfilename && strlen(pfilename) > 30 &&
  86. strchr(pfilename,'/') != NULL ; pfilename++ )
  87. pfilename= strchr(pfilename,'/');
  88. if (pfilename && pfilename != filename) {
  89. pfilenamebuf= (char *)nfmalloc(strlen(pfilename)+5);
  90. strcpy(pfilenamebuf,".../");
  91. strcat(pfilenamebuf,pfilename);
  92. pfilename= pfilenamebuf;
  93. } else {
  94. pfilename= filename;
  95. }
  96. if (stat(filename,&stab)) ohshite(_("cannot access archive"));
  97. if (!f_noact) {
  98. /* We can't `tentatively-reassemble' packages. */
  99. if (!reasmbuf) {
  100. reasmbuf= m_malloc(admindirlen+sizeof(REASSEMBLETMP)+5);
  101. strcpy(reasmbuf,admindir);
  102. strcat(reasmbuf,"/" REASSEMBLETMP);
  103. }
  104. if (unlink(reasmbuf) && errno != ENOENT)
  105. ohshite(_("error ensuring `%.250s' doesn't exist"),reasmbuf);
  106. push_cleanup(cu_pathname, ~0, NULL, 0, 1, (void *)reasmbuf);
  107. c1= m_fork();
  108. if (!c1) {
  109. execlp(SPLITTER, SPLITTER, "-Qao", reasmbuf, filename, NULL);
  110. ohshite(_("failed to exec dpkg-split to see if it's part of a multiparter"));
  111. }
  112. while ((r= waitpid(c1,&status,0)) == -1 && errno == EINTR);
  113. if (r != c1) { onerr_abort++; ohshite(_("wait for dpkg-split failed")); }
  114. switch (WIFEXITED(status) ? WEXITSTATUS(status) : -1) {
  115. case 0:
  116. /* It was a part - is it complete ? */
  117. if (!stat(reasmbuf,&stab)) { /* Yes. */
  118. filename= reasmbuf;
  119. pfilename= _("reassembled package file");
  120. break;
  121. } else if (errno == ENOENT) { /* No. That's it, we skip it. */
  122. return;
  123. }
  124. case 1:
  125. /* No, it wasn't a part. */
  126. break;
  127. default:
  128. checksubprocerr(status,SPLITTER,0);
  129. }
  130. }
  131. /* Verify the package. */
  132. if (!f_nodebsig && (stat(DEBSIGVERIFY, &stab)==0)) {
  133. printf(_("Authenticating %s ...\n"), filename);
  134. fflush(stdout);
  135. c1 = m_fork();
  136. if (!c1) {
  137. execl(DEBSIGVERIFY, DEBSIGVERIFY, "-q", filename, NULL);
  138. ohshite(_("failed to execl debsig-verify"));
  139. } else {
  140. int status;
  141. waitpid(c1, &status, 0);
  142. if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
  143. if (! fc_badverify) {
  144. ohshit(_("Verification on package %s failed!"), filename);
  145. } else {
  146. fprintf(stderr, _("Verification on package %s failed,\nbut installing anyway as you request.\n"), filename);
  147. }
  148. } else {
  149. printf(_("passed\n"));
  150. }
  151. }
  152. }
  153. if (f_noact) {
  154. cidir= cidirtmpnambuf;
  155. /* We use tmpnam here, not to get a unique filename, but to get a unique directory. */
  156. if (!tmpnam(cidir)) ohshite(_("unable to get unique filename for control info"));
  157. strcat(cidir,"/");
  158. } else {
  159. /* We want it to be on the same filesystem so that we can
  160. * use rename(2) to install the postinst &c.
  161. */
  162. if (!cidirbuf)
  163. cidirbuf= m_malloc(admindirlen+sizeof(CONTROLDIRTMP)+MAXCONTROLFILENAME+10);
  164. cidir= cidirbuf;
  165. strcpy(cidir,admindir);
  166. strcat(cidir, "/" CONTROLDIRTMP);
  167. }
  168. cidirrest= cidir + strlen(cidir);
  169. assert(*cidir && cidirrest[-1] == '/'); cidirrest[-1]= 0;
  170. ensure_pathname_nonexisting(cidir); cidirrest[-1]= '/';
  171. push_cleanup(cu_cidir, ~0, NULL, 0, 2, (void *)cidir, (void *)cidirrest);
  172. c1= m_fork();
  173. if (!c1) {
  174. cidirrest[-1]= 0;
  175. execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL);
  176. ohshite(_("failed to exec dpkg-deb to extract control information"));
  177. }
  178. waitsubproc(c1,BACKEND " --control",0);
  179. strcpy(cidirrest,CONTROLFILE);
  180. parsedb(cidir, pdb_recordavailable | pdb_rejectstatus | pdb_ignorefiles,
  181. &pkg,NULL,NULL);
  182. if (!pkg->files) {
  183. pkg->files= nfmalloc(sizeof(struct filedetails));
  184. pkg->files->next = NULL;
  185. pkg->files->name = pkg->files->msdosname = pkg->files->md5sum = NULL;
  186. }
  187. /* Always nfmalloc. Otherwise, we may overwrite some other field(like md5sum). */
  188. psize = nfmalloc(30);
  189. sprintf(psize, "%lu", (unsigned long)stab.st_size);
  190. pkg->files->size = psize;
  191. if (cipaction->arg == act_avail) {
  192. printf(_("Recorded info about %s from %s.\n"),pkg->name,pfilename);
  193. pop_cleanup(ehflag_normaltidy);
  194. return;
  195. }
  196. if (pkg->available.architecture && *pkg->available.architecture &&
  197. strcmp(pkg->available.architecture,"all") &&
  198. strcmp(pkg->available.architecture,architecture))
  199. forcibleerr(fc_architecture,
  200. _("package architecture (%s) does not match system (%s)"),
  201. pkg->available.architecture,architecture);
  202. if (!pkg->installed.valid) blankpackageperfile(&pkg->installed);
  203. assert(pkg->available.valid);
  204. for (deconpil= deconfigure;
  205. deconpil;
  206. deconpil= deconpiltemp) {
  207. deconpiltemp= deconpil->next;
  208. free(deconpil);
  209. }
  210. deconfigure = NULL;
  211. clear_istobes();
  212. if (!wanttoinstall(pkg,&pkg->available.version,1)) {
  213. pop_cleanup(ehflag_normaltidy);
  214. return;
  215. }
  216. /* Check if anything is installed that we conflict with, or not installed
  217. * that we need */
  218. pkg->clientdata->istobe= itb_installnew;
  219. for (dsearch= pkg->available.depends; dsearch; dsearch= dsearch->next) {
  220. switch (dsearch->type) {
  221. case dep_conflicts:
  222. /* Look for things we conflict with. */
  223. check_conflict(dsearch, pkg, pfilename);
  224. break;
  225. case dep_breaks:
  226. /* Look for things we break. */
  227. check_breaks(dsearch, pkg, pfilename);
  228. break;
  229. case dep_provides:
  230. /* Look for things that conflict with what we provide. */
  231. if (dsearch->list->ed->installed.valid) {
  232. for (psearch= dsearch->list->ed->installed.depended;
  233. psearch;
  234. psearch= psearch->nextrev) {
  235. if (psearch->up->type != dep_conflicts) continue;
  236. check_conflict(psearch->up, pkg, pfilename);
  237. }
  238. }
  239. break;
  240. case dep_suggests:
  241. case dep_recommends:
  242. case dep_depends:
  243. case dep_replaces:
  244. case dep_enhances:
  245. /* Ignore these here. */
  246. break;
  247. case dep_predepends:
  248. if (!depisok(dsearch, &depprobwhy, NULL, 1)) {
  249. varbufaddc(&depprobwhy,0);
  250. fprintf(stderr, _("dpkg: regarding %s containing %s, pre-dependency problem:\n%s"),
  251. pfilename, pkg->name, depprobwhy.buf);
  252. if (!force_depends(dsearch->list))
  253. ohshit(_("pre-dependency problem - not installing %.250s"),pkg->name);
  254. fprintf(stderr, _("dpkg: warning - ignoring pre-dependency problem !\n"));
  255. }
  256. }
  257. }
  258. /* Look for things that conflict with us. */
  259. for (psearch= pkg->installed.depended; psearch; psearch= psearch->nextrev) {
  260. if (psearch->up->type != dep_conflicts) continue;
  261. check_conflict(psearch->up, pkg, pfilename);
  262. }
  263. ensure_allinstfiles_available();
  264. filesdbinit();
  265. trig_file_interests_ensure();
  266. if (pkg->status != stat_notinstalled && pkg->status != stat_configfiles) {
  267. printf(_("Preparing to replace %s %s (using %s) ...\n"),
  268. pkg->name,
  269. versiondescribe(&pkg->installed.version,vdew_nonambig),
  270. pfilename);
  271. log_action("upgrade", pkg);
  272. } else {
  273. printf(_("Unpacking %s (from %s) ...\n"),pkg->name,pfilename);
  274. log_action("install", pkg);
  275. }
  276. if (f_noact) {
  277. pop_cleanup(ehflag_normaltidy);
  278. return;
  279. }
  280. /*
  281. * OK, we're going ahead.
  282. */
  283. trig_activate_packageprocessing(pkg);
  284. strcpy(cidirrest, TRIGGERSCIFILE);
  285. trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg);
  286. /* Read the conffiles, and copy the hashes across. */
  287. newconffiles = NULL;
  288. newconffileslastp = &newconffiles;
  289. push_cleanup(cu_fileslist, ~0, NULL, 0, 0);
  290. strcpy(cidirrest,CONFFILESFILE);
  291. conff= fopen(cidir,"r");
  292. if (conff) {
  293. push_cleanup(cu_closefile, ehflag_bombout, NULL, 0, 1, (void *)conff);
  294. while (fgets(conffilenamebuf,MAXCONFFILENAME-2,conff)) {
  295. p= conffilenamebuf + strlen(conffilenamebuf);
  296. assert(p != conffilenamebuf);
  297. if (p[-1] != '\n')
  298. ohshit(_("name of conffile (starting `%.250s') is too long (>%d characters)"),
  299. conffilenamebuf, MAXCONFFILENAME);
  300. while (p > conffilenamebuf && isspace(p[-1])) --p;
  301. if (p == conffilenamebuf) continue;
  302. *p= 0;
  303. namenode= findnamenode(conffilenamebuf, 0);
  304. namenode->oldhash= NEWCONFFILEFLAG;
  305. newconff= newconff_append(&newconffileslastp, namenode);
  306. /* Let's see if any packages have this file. If they do we
  307. * check to see if they listed it as a conffile, and if they did
  308. * we copy the hash across. Since (for plain file conffiles,
  309. * which is the only kind we are supposed to have) there will
  310. * only be one package which `has' the file, this will usually
  311. * mean we only look in the package which we're installing now.
  312. * The `conffiles' data in the status file is ignored when a
  313. * package isn't also listed in the file ownership database as
  314. * having that file. If several packages are listed as owning
  315. * the file we pick one at random.
  316. */
  317. searchconff = NULL;
  318. for (packageslump= newconff->namenode->packages;
  319. packageslump;
  320. packageslump= packageslump->more) {
  321. for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) {
  322. otherpkg= packageslump->pkgs[i];
  323. debug(dbg_conffdetail,"process_archive conffile `%s' in package %s - conff ?",
  324. newconff->namenode->name,otherpkg->name);
  325. for (searchconff= otherpkg->installed.conffiles;
  326. searchconff && strcmp(newconff->namenode->name,searchconff->name);
  327. searchconff= searchconff->next)
  328. debug(dbg_conffdetail,
  329. "process_archive conffile `%s' in package %s - conff ? not `%s'",
  330. newconff->namenode->name,otherpkg->name,searchconff->name);
  331. if (searchconff) {
  332. debug(dbg_conff,"process_archive conffile `%s' package=%s %s hash=%s",
  333. newconff->namenode->name,otherpkg->name,
  334. otherpkg == pkg ? "same" : "different!",
  335. searchconff->hash);
  336. if (otherpkg == pkg) goto xit_conff_hashcopy_srch;
  337. }
  338. }
  339. }
  340. xit_conff_hashcopy_srch:
  341. if (searchconff) {
  342. newconff->namenode->oldhash= searchconff->hash;
  343. /* we don't copy `obsolete'; it's not obsolete in the new package */
  344. } else {
  345. debug(dbg_conff,"process_archive conffile `%s' no package, no hash",
  346. newconff->namenode->name);
  347. }
  348. newconff->namenode->flags |= fnnf_new_conff;
  349. }
  350. if (ferror(conff)) ohshite(_("read error in %.250s"),cidir);
  351. pop_cleanup(ehflag_normaltidy); /* conff= fopen() */
  352. if (fclose(conff)) ohshite(_("error closing %.250s"),cidir);
  353. } else {
  354. if (errno != ENOENT) ohshite(_("error trying to open %.250s"),cidir);
  355. }
  356. /* All the old conffiles are marked with a flag, so that we don't delete
  357. * them if they seem to disappear completely.
  358. */
  359. oldconffsetflags(pkg->installed.conffiles);
  360. for (i = 0 ; i < cflict_index ; i++) {
  361. oldconffsetflags(conflictor[i]->installed.conffiles);
  362. }
  363. oldversionstatus= pkg->status;
  364. assert(oldversionstatus <= stat_installed);
  365. debug(dbg_general,"process_archive oldversionstatus=%s",
  366. statusstrings[oldversionstatus]);
  367. if (oldversionstatus == stat_halfconfigured ||
  368. oldversionstatus == stat_triggersawaited ||
  369. oldversionstatus == stat_triggerspending ||
  370. oldversionstatus == stat_installed) {
  371. pkg->eflag |= eflagf_reinstreq;
  372. pkg->status= stat_halfconfigured;
  373. modstatdb_note(pkg);
  374. push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg);
  375. maintainer_script_alternative(pkg, PRERMFILE, "pre-removal", cidir, cidirrest,
  376. "upgrade", "failed-upgrade");
  377. pkg->status= stat_unpacked;
  378. oldversionstatus= stat_unpacked;
  379. modstatdb_note(pkg);
  380. }
  381. for (deconpil= deconfigure; deconpil; deconpil= deconpil->next) {
  382. struct pkginfo *removing = deconpil->pkg_removal;
  383. if (removing)
  384. printf(_("De-configuring %s, to allow removal of %s ...\n"),
  385. deconpil->pkg->name, removing->name);
  386. else
  387. printf(_("De-configuring %s ...\n"), deconpil->pkg->name);
  388. trig_activate_packageprocessing(deconpil->pkg);
  389. deconpil->pkg->status= stat_halfconfigured;
  390. modstatdb_note(deconpil->pkg);
  391. /* This means that we *either* go and run postinst abort-deconfigure,
  392. * *or* queue the package for later configure processing, depending
  393. * on which error cleanup route gets taken.
  394. */
  395. push_cleanup(cu_prermdeconfigure, ~ehflag_normaltidy,
  396. ok_prermdeconfigure, ehflag_normaltidy,
  397. 3, (void*)deconpil->pkg, (void*)removing, (void*)pkg);
  398. if (removing) {
  399. maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal",
  400. "deconfigure", "in-favour", pkg->name,
  401. versiondescribe(&pkg->available.version,
  402. vdew_nonambig),
  403. "removing", removing->name,
  404. versiondescribe(&removing->installed.version,
  405. vdew_nonambig),
  406. NULL);
  407. } else {
  408. maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal",
  409. "deconfigure", "in-favour", pkg->name,
  410. versiondescribe(&pkg->available.version,
  411. vdew_nonambig),
  412. NULL);
  413. }
  414. }
  415. for (i = 0 ; i < cflict_index; i++) {
  416. if (!(conflictor[i]->status == stat_halfconfigured ||
  417. conflictor[i]->status == stat_triggersawaited ||
  418. conflictor[i]->status == stat_triggerspending ||
  419. conflictor[i]->status == stat_installed)) continue;
  420. trig_activate_packageprocessing(conflictor[i]);
  421. conflictor[i]->status= stat_halfconfigured;
  422. modstatdb_note(conflictor[i]);
  423. push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, NULL, 0,
  424. 2,(void*)conflictor[i],(void*)pkg);
  425. maintainer_script_installed(conflictor[i], PRERMFILE, "pre-removal",
  426. "remove", "in-favour", pkg->name,
  427. versiondescribe(&pkg->available.version,
  428. vdew_nonambig),
  429. NULL);
  430. conflictor[i]->status= stat_halfinstalled;
  431. modstatdb_note(conflictor[i]);
  432. }
  433. pkg->eflag |= eflagf_reinstreq;
  434. if (pkg->status == stat_notinstalled)
  435. pkg->installed.version= pkg->available.version;
  436. pkg->status= stat_halfinstalled;
  437. modstatdb_note(pkg);
  438. if (oldversionstatus == stat_notinstalled) {
  439. push_cleanup(cu_preinstverynew, ~ehflag_normaltidy, NULL, 0,
  440. 3,(void*)pkg,(void*)cidir,(void*)cidirrest);
  441. maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
  442. "install", NULL);
  443. } else if (oldversionstatus == stat_configfiles) {
  444. push_cleanup(cu_preinstnew, ~ehflag_normaltidy, NULL, 0,
  445. 3,(void*)pkg,(void*)cidir,(void*)cidirrest);
  446. maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
  447. "install", versiondescribe(&pkg->installed.version,
  448. vdew_nonambig),
  449. NULL);
  450. } else {
  451. push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0,
  452. 4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus);
  453. maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
  454. "upgrade", versiondescribe(&pkg->installed.version,
  455. vdew_nonambig),
  456. NULL);
  457. printf(_("Unpacking replacement %.250s ...\n"),pkg->name);
  458. }
  459. /*
  460. * Now we unpack the archive, backing things up as we go.
  461. * For each file, we check to see if it already exists.
  462. * There are several possibilities:
  463. * + We are trying to install a non-directory ...
  464. * - It doesn't exist. In this case we simply extract it.
  465. * - It is a plain file, device, symlink, &c. We do an `atomic
  466. * overwrite' using link() and rename(), but leave a backup copy.
  467. * Later, when we delete the backup, we remove it from any other
  468. * packages' lists.
  469. * - It is a directory. In this case it depends on whether we're
  470. * trying to install a symlink or something else.
  471. * = If we're not trying to install a symlink we move the directory
  472. * aside and extract the node. Later, when we recursively remove
  473. * the backed-up directory, we remove it from any other packages'
  474. * lists.
  475. * = If we are trying to install a symlink we do nothing - ie,
  476. * dpkg will never replace a directory tree with a symlink. This
  477. * is to avoid embarrassing effects such as replacing a directory
  478. * tree with a link to a link to the original directory tree.
  479. * + We are trying to install a directory ...
  480. * - It doesn't exist. We create it with the appropriate modes.
  481. * - It exists as a directory or a symlink to one. We do nothing.
  482. * - It is a plain file or a symlink (other than to a directory).
  483. * We move it aside and create the directory. Later, when we
  484. * delete the backup, we remove it from any other packages' lists.
  485. *
  486. * Install non-dir Install symlink Install dir
  487. * Exists not X X X
  488. * File/node/symlink LXR LXR BXR
  489. * Directory BXR - -
  490. *
  491. * X: extract file/node/link/directory
  492. * LX: atomic overwrite leaving backup
  493. * B: ordinary backup
  494. * R: later remove from other packages' lists
  495. * -: do nothing
  496. *
  497. * After we've done this we go through the remaining things in the
  498. * lists of packages we're trying to remove (including the old
  499. * version of the current package). This happens in reverse order,
  500. * so that we process files before the directories (or symlinks-to-
  501. * directories) containing them.
  502. * + If the thing is a conffile then we leave it alone for the purge
  503. * operation.
  504. * + Otherwise, there are several possibilities too:
  505. * - The listed thing does not exist. We ignore it.
  506. * - The listed thing is a directory or a symlink to a directory.
  507. * We delete it only if it isn't listed in any other package.
  508. * - The listed thing is not a directory, but was part of the package
  509. * that was upgraded, we check to make sure the files aren't the
  510. * same ones from the old package by checking dev/inode
  511. * - The listed thing is not a directory or a symlink to one (ie,
  512. * it's a plain file, device, pipe, &c, or a symlink to one, or a
  513. * dangling symlink). We delete it.
  514. * The removed packages' list becomes empty (of course, the new
  515. * version of the package we're installing will have a new list,
  516. * which replaces the old version's list).
  517. *
  518. * If at any stage we remove a file from a package's list, and the
  519. * package isn't one we're already processing, and the package's
  520. * list becomes empty as a result, we `vanish' the package. This
  521. * means that we run its postrm with the `disappear' argument, and
  522. * put the package in the `not-installed' state. If it had any
  523. * conffiles, their hashes and ownership will have been transferred
  524. * already, so we just ignore those and forget about them from the
  525. * point of view of the disappearing package.
  526. *
  527. * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the
  528. * files get replaced `as we go'.
  529. */
  530. m_pipe(p1);
  531. push_cleanup(cu_closepipe, ehflag_bombout, NULL, 0, 1, (void *)&p1[0]);
  532. c1= m_fork();
  533. if (!c1) {
  534. m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
  535. execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL);
  536. ohshite(_("unable to exec dpkg-deb to get filesystem archive"));
  537. }
  538. close(p1[1]);
  539. p1[1] = -1;
  540. newfileslist = NULL;
  541. tc.newfilesp = &newfileslist;
  542. push_cleanup(cu_fileslist, ~0, NULL, 0, 0);
  543. tc.pkg= pkg;
  544. tc.backendpipe= p1[0];
  545. r= TarExtractor((void*)&tc, &tf);
  546. if (r) {
  547. if (errno) {
  548. ohshite(_("error reading dpkg-deb tar output"));
  549. } else {
  550. ohshit(_("corrupted filesystem tarfile - corrupted package archive"));
  551. }
  552. }
  553. fd_null_copy(p1[0], -1, _("dpkg-deb: zap possible trailing zeros"));
  554. close(p1[0]);
  555. p1[0] = -1;
  556. waitsubproc(c1,BACKEND " --fsys-tarfile",PROCPIPE);
  557. if (oldversionstatus == stat_halfinstalled || oldversionstatus == stat_unpacked) {
  558. /* Packages that were in `installed' and `postinstfailed' have been reduced
  559. * to `unpacked' by now, by the running of the prerm script.
  560. */
  561. pkg->status= stat_halfinstalled;
  562. modstatdb_note(pkg);
  563. push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg);
  564. maintainer_script_alternative(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
  565. "upgrade", "failed-upgrade");
  566. }
  567. /* If anything goes wrong while tidying up it's a bit late to do
  568. * anything about it. However, we don't install the new status
  569. * info yet, so that a future dpkg installation will put everything
  570. * right (we hope).
  571. *
  572. * If something does go wrong later the `conflictor' package will be
  573. * left in the `removal_failed' state. Removing or installing it
  574. * will be impossible if it was required because of the conflict with
  575. * the package we're installing now and (presumably) the dependency
  576. * by other packages. This means that the files it contains in
  577. * common with this package will hang around until we successfully
  578. * get this package installed, after which point we can trust the
  579. * conflicting package's file list, which will have been updated to
  580. * remove any files in this package.
  581. */
  582. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  583. /* Now we delete all the files that were in the old version of
  584. * the package only, except (old or new) conffiles, which we leave
  585. * alone.
  586. */
  587. reversefilelist_init(&rlistit,pkg->clientdata->files);
  588. while ((namenode= reversefilelist_next(&rlistit))) {
  589. struct filenamenode *usenode;
  590. if ((namenode->flags & fnnf_new_conff) ||
  591. (namenode->flags & fnnf_new_inarchive))
  592. continue;
  593. usenode = namenodetouse(namenode, pkg);
  594. trig_file_activate(usenode, pkg);
  595. fnamevb.used= fnameidlu;
  596. varbufaddstr(&fnamevb, usenode->name);
  597. varbufaddc(&fnamevb,0);
  598. if (!stat(namenode->name,&stab) && S_ISDIR(stab.st_mode)) {
  599. debug(dbg_eachfiledetail, "process_archive: %s is a directory",
  600. namenode->name);
  601. if (isdirectoryinuse(namenode,pkg)) continue;
  602. }
  603. if (lstat(fnamevb.buf, &oldfs)) {
  604. if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
  605. fprintf(stderr,
  606. _("dpkg: warning - could not stat old file `%.250s'"
  607. " so not deleting it: %s"),
  608. fnamevb.buf, strerror(errno));
  609. continue;
  610. }
  611. if (S_ISDIR(oldfs.st_mode)) {
  612. if (rmdir(fnamevb.buf)) {
  613. fprintf(stderr,
  614. _("dpkg: warning - unable to delete old directory"
  615. " `%.250s': %s\n"), namenode->name, strerror(errno));
  616. } else if ((namenode->flags & fnnf_old_conff)) {
  617. fprintf(stderr,
  618. _("dpkg: warning - old conffile `%.250s' was an empty"
  619. " directory (and has now been deleted)\n"),
  620. namenode->name);
  621. }
  622. } else {
  623. /* Ok, it's an old file, but is it really not in the new package?
  624. * It might be known by a different name because of symlinks.
  625. *
  626. * We need to check to make sure, so we stat the file, then compare
  627. * it to the new list. If we find a dev/inode match, we assume they
  628. * are the same file, and leave it alone. NOTE: we don't check in
  629. * other packages for sanity reasons (we don't want to stat _all_
  630. * the files on the system).
  631. *
  632. * We run down the list of _new_ files in this package. This keeps
  633. * the process a little leaner. We are only worried about new ones
  634. * since ones that stayed the same don't really apply here.
  635. */
  636. struct fileinlist *sameas = NULL;
  637. static struct stat empty_stat;
  638. struct varbuf cfilename = VARBUF_INIT;
  639. /* If we can't stat the old or new file, or it's a directory,
  640. * we leave it up to the normal code
  641. */
  642. debug(dbg_eachfile, "process_archive: checking %s for same files on "
  643. "upgrade/downgrade", fnamevb.buf);
  644. for (cfile= newfileslist; cfile; cfile= cfile->next) {
  645. if (!cfile->namenode->filestat) {
  646. struct stat tmp_stat;
  647. varbufreset(&cfilename);
  648. varbufaddstr(&cfilename, instdir);
  649. varbufaddc(&cfilename, '/');
  650. varbufaddstr(&cfilename, cfile->namenode->name);
  651. varbufaddc(&cfilename, '\0');
  652. if (lstat(cfilename.buf, &tmp_stat) == 0) {
  653. cfile->namenode->filestat = nfmalloc(sizeof(struct stat));
  654. memcpy(cfile->namenode->filestat, &tmp_stat, sizeof(struct stat));
  655. } else {
  656. if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
  657. ohshite(_("unable to stat other new file `%.250s'"),
  658. cfile->namenode->name);
  659. cfile->namenode->filestat = &empty_stat;
  660. continue;
  661. }
  662. }
  663. if (cfile->namenode->filestat == &empty_stat)
  664. continue;
  665. if (oldfs.st_dev == cfile->namenode->filestat->st_dev &&
  666. oldfs.st_ino == cfile->namenode->filestat->st_ino) {
  667. if (sameas)
  668. fprintf(stderr, _("dpkg: warning - old file `%.250s' is the same"
  669. " as several new files! (both `%.250s' and `%.250s')\n"),
  670. fnamevb.buf,
  671. sameas->namenode->name, cfile->namenode->name);
  672. sameas= cfile;
  673. debug(dbg_eachfile, "process_archive: not removing %s,"
  674. " since it matches %s", fnamevb.buf, cfile->namenode->name);
  675. }
  676. }
  677. varbuffree(&cfilename);
  678. if ((namenode->flags & fnnf_old_conff)) {
  679. if (sameas) {
  680. if (sameas->namenode->flags & fnnf_new_conff) {
  681. if (!strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG)) {
  682. sameas->namenode->oldhash= namenode->oldhash;
  683. debug(dbg_eachfile, "process_archive: old conff %s"
  684. " is same as new conff %s, copying hash",
  685. namenode->name, sameas->namenode->name);
  686. } else {
  687. debug(dbg_eachfile, "process_archive: old conff %s"
  688. " is same as new conff %s but latter already has hash",
  689. namenode->name, sameas->namenode->name);
  690. }
  691. }
  692. } else {
  693. debug(dbg_eachfile, "process_archive: old conff %s"
  694. " is disappearing", namenode->name);
  695. namenode->flags |= fnnf_obs_conff;
  696. newconff_append(&newconffileslastp, namenode);
  697. addfiletolist(&tc, namenode);
  698. }
  699. continue;
  700. }
  701. if (sameas)
  702. continue;
  703. failed= N_("delete");
  704. if (chmodsafe_unlink_statted(fnamevb.buf, &oldfs, &failed)) {
  705. const char *failed_local = gettext(failed);
  706. fprintf(stderr, _("dpkg: warning - unable to %s old file '%.250s': %s\n"),
  707. failed_local, namenode->name, strerror(errno));
  708. }
  709. } /* !S_ISDIR */
  710. }
  711. /* OK, now we can write the updated files-in-this package list,
  712. * since we've done away (hopefully) with all the old junk.
  713. */
  714. write_filelist_except(pkg,newfileslist,0);
  715. /* Trigger interests may have changed.
  716. * Firstly we go through the old list of interests deleting them.
  717. * Then we go through the new list adding them.
  718. */
  719. strcpy(cidirrest, TRIGGERSCIFILE);
  720. trig_parse_ci(pkgadminfile(pkg, TRIGGERSCIFILE),
  721. trig_cicb_interest_delete, NULL, pkg);
  722. trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg);
  723. trig_file_interests_save();
  724. /* We also install the new maintainer scripts, and any other
  725. * cruft that may have come along with the package. First
  726. * we go through the existing scripts replacing or removing
  727. * them as appropriate; then we go through the new scripts
  728. * (any that are left) and install them.
  729. */
  730. debug(dbg_general, "process_archive updating info directory");
  731. varbufreset(&infofnvb);
  732. varbufaddstr(&infofnvb,admindir);
  733. varbufaddstr(&infofnvb,"/" INFODIR "/");
  734. infodirlen= infofnvb.used;
  735. varbufaddc(&infofnvb,0);
  736. dsd= opendir(infofnvb.buf);
  737. if (!dsd) ohshite(_("cannot read info directory"));
  738. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  739. while ((de = readdir(dsd)) != NULL) {
  740. debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name);
  741. if (de->d_name[0] == '.') continue; /* ignore dotfiles, including `.' and `..' */
  742. p= strrchr(de->d_name,'.'); if (!p) continue; /* ignore anything odd */
  743. if (strlen(pkg->name) != (size_t)(p-de->d_name) ||
  744. strncmp(de->d_name,pkg->name,p-de->d_name)) continue;
  745. debug(dbg_stupidlyverbose, "process_archive info this pkg");
  746. /* Right do we have one ? */
  747. p++; /* skip past the full stop */
  748. if (!strcmp(p,LISTFILE)) continue; /* We do the list separately */
  749. if (strlen(p) > MAXCONTROLFILENAME)
  750. ohshit(_("old version of package has overly-long info file name starting `%.250s'"),
  751. de->d_name);
  752. infofnvb.used= infodirlen;
  753. varbufaddstr(&infofnvb,de->d_name);
  754. varbufaddc(&infofnvb,0);
  755. strcpy(cidirrest,p);
  756. if (!rename(cidir,infofnvb.buf)) {
  757. debug(dbg_scripts, "process_archive info installed %s as %s",
  758. cidir, infofnvb.buf);
  759. } else if (errno == ENOENT) {
  760. /* Right, no new version. */
  761. if (unlink(infofnvb.buf))
  762. ohshite(_("unable to remove obsolete info file `%.250s'"),infofnvb.buf);
  763. debug(dbg_scripts, "process_archive info unlinked %s",infofnvb.buf);
  764. } else {
  765. ohshite(_("unable to install (supposed) new info file `%.250s'"),cidir);
  766. }
  767. }
  768. pop_cleanup(ehflag_normaltidy); /* closedir */
  769. *cidirrest= 0; /* the directory itself */
  770. dsd= opendir(cidir);
  771. if (!dsd) ohshite(_("unable to open temp control directory"));
  772. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  773. while ((de= readdir(dsd))) {
  774. if (strchr(de->d_name,'.')) {
  775. debug(dbg_scripts,"process_archive tmp.ci script/file `%s' contains dot",
  776. de->d_name);
  777. continue;
  778. }
  779. if (strlen(de->d_name) > MAXCONTROLFILENAME)
  780. ohshit(_("package contains overly-long control info file name (starting `%.50s')"),
  781. de->d_name);
  782. strcpy(cidirrest,de->d_name);
  783. /* First we check it's not a directory. */
  784. if (!rmdir(cidir))
  785. ohshit(_("package control info contained directory `%.250s'"),cidir);
  786. else if (errno != ENOTDIR)
  787. ohshite(_("package control info rmdir of `%.250s' didn't say not a dir"),de->d_name);
  788. if (!strcmp(de->d_name,CONTROLFILE)) {
  789. debug(dbg_scripts,"process_archive tmp.ci script/file `%s' is control",cidir);
  790. continue; /* ignore the control file */
  791. }
  792. if (!strcmp(de->d_name,LISTFILE)) {
  793. fprintf(stderr, _("dpkg: warning - package %s"
  794. " contained list as info file"), pkg->name);
  795. continue;
  796. }
  797. /* Right, install it */
  798. newinfofilename= pkgadminfile(pkg,de->d_name);
  799. if (rename(cidir,newinfofilename))
  800. ohshite(_("unable to install new info file `%.250s' as `%.250s'"),
  801. cidir,newinfofilename);
  802. debug(dbg_scripts,"process_archive tmp.ci script/file `%s' installed as `%s'",
  803. cidir, newinfofilename);
  804. }
  805. pop_cleanup(ehflag_normaltidy); /* closedir */
  806. /* Update the status database.
  807. * This involves copying each field across from the `available'
  808. * to the `installed' half of the pkg structure.
  809. * For some of the fields we have to do a complicated construction
  810. * operation; for others we can just copy the value.
  811. * We tackle the fields in the order they appear, so that
  812. * we don't miss any out :-).
  813. * At least we don't have to copy any strings that are referred
  814. * to, because these are never modified and never freed.
  815. */
  816. /* The dependencies are the most difficult. We have to build
  817. * a whole new forward dependency tree. At least the reverse
  818. * links (linking our deppossi's into the reverse chains)
  819. * can be done by copy_dependency_links.
  820. */
  821. newdeplist = NULL;
  822. newdeplistlastp = &newdeplist;
  823. for (dep= pkg->available.depends; dep; dep= dep->next) {
  824. newdep= nfmalloc(sizeof(struct dependency));
  825. newdep->up= pkg;
  826. newdep->next = NULL;
  827. newdep->list = NULL;
  828. newpossilastp = &newdep->list;
  829. for (possi= dep->list; possi; possi= possi->next) {
  830. newpossi= nfmalloc(sizeof(struct deppossi));
  831. newpossi->up= newdep;
  832. newpossi->ed= possi->ed;
  833. newpossi->next = NULL;
  834. newpossi->nextrev = newpossi->backrev = NULL;
  835. newpossi->verrel= possi->verrel;
  836. if (possi->verrel != dvr_none)
  837. newpossi->version= possi->version;
  838. else
  839. blankversion(&newpossi->version);
  840. newpossi->cyclebreak= 0;
  841. *newpossilastp= newpossi;
  842. newpossilastp= &newpossi->next;
  843. }
  844. newdep->type= dep->type;
  845. *newdeplistlastp= newdep;
  846. newdeplistlastp= &newdep->next;
  847. }
  848. /* Right, now we've replicated the forward tree, we
  849. * get copy_dependency_links to remove all the old dependency
  850. * structures from the reverse links and add the new dependency
  851. * structures in instead. It also copies the new dependency
  852. * structure pointer for this package into the right field.
  853. */
  854. copy_dependency_links(pkg,&pkg->installed.depends,newdeplist,0);
  855. /* The `depended' pointer in the structure doesn't represent anything
  856. * that is actually specified by this package - it's there so we
  857. * can find out what other packages refer to this one. So,
  858. * we don't copy it. We go straight on to copy the text fields.
  859. */
  860. pkg->installed.essential= pkg->available.essential;
  861. pkg->installed.description= pkg->available.description;
  862. pkg->installed.maintainer= pkg->available.maintainer;
  863. pkg->installed.source= pkg->available.source;
  864. pkg->installed.architecture= pkg->available.architecture;
  865. pkg->installed.installedsize= pkg->available.installedsize;
  866. pkg->installed.version= pkg->available.version;
  867. pkg->installed.origin = pkg->available.origin;
  868. pkg->installed.bugs = pkg->available.bugs;
  869. /* We have to generate our own conffiles structure. */
  870. pkg->installed.conffiles = NULL;
  871. iconffileslastp = &pkg->installed.conffiles;
  872. for (cfile= newconffiles; cfile; cfile= cfile->next) {
  873. newiconff= nfmalloc(sizeof(struct conffile));
  874. newiconff->next = NULL;
  875. newiconff->name= nfstrsave(cfile->namenode->name);
  876. newiconff->hash= nfstrsave(cfile->namenode->oldhash);
  877. newiconff->obsolete= !!(cfile->namenode->flags & fnnf_obs_conff);
  878. *iconffileslastp= newiconff;
  879. iconffileslastp= &newiconff->next;
  880. }
  881. /* We can just copy the arbitrary fields list, because it is
  882. * never even rearragned. Phew !
  883. */
  884. pkg->installed.arbs= pkg->available.arbs;
  885. /* Check for disappearing packages:
  886. * We go through all the packages on the system looking for ones
  887. * whose files are entirely part of the one we've just unpacked
  888. * (and which actually *have* some files!).
  889. *
  890. * Any that we find are removed - we run the postrm with `disappear'
  891. * as an argument, and remove their info/... files and status info.
  892. * Conffiles are ignored (the new package had better do something
  893. * with them !).
  894. */
  895. it= iterpkgstart();
  896. while ((otherpkg = iterpkgnext(it)) != NULL) {
  897. ensure_package_clientdata(otherpkg);
  898. if (otherpkg == pkg ||
  899. otherpkg->status == stat_notinstalled ||
  900. otherpkg->status == stat_configfiles ||
  901. otherpkg->clientdata->istobe == itb_remove ||
  902. !otherpkg->clientdata->files) continue;
  903. debug(dbg_veryverbose, "process_archive checking disappearance %s",otherpkg->name);
  904. assert(otherpkg->clientdata->istobe == itb_normal ||
  905. otherpkg->clientdata->istobe == itb_deconfigure);
  906. for (cfile= otherpkg->clientdata->files;
  907. cfile && !strcmp(cfile->namenode->name,"/.");
  908. cfile= cfile->next);
  909. if (!cfile) {
  910. debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear");
  911. continue;
  912. }
  913. for (cfile= otherpkg->clientdata->files;
  914. cfile && !filesavespackage(cfile,otherpkg,pkg);
  915. cfile= cfile->next);
  916. if (cfile) continue;
  917. /* So dependency things will give right answers ... */
  918. otherpkg->clientdata->istobe= itb_remove;
  919. debug(dbg_veryverbose, "process_archive disappear checking dependencies");
  920. for (pdep= otherpkg->installed.depended;
  921. pdep;
  922. pdep= pdep->nextrev) {
  923. if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends &&
  924. pdep->up->type != dep_recommends) continue;
  925. if (depisok(pdep->up, &depprobwhy, NULL, 0))
  926. continue;
  927. varbufaddc(&depprobwhy,0);
  928. debug(dbg_veryverbose,"process_archive cannot disappear: %s",depprobwhy.buf);
  929. break;
  930. }
  931. if (!pdep) {
  932. /* If we haven't found a reason not to yet, let's look some more. */
  933. for (providecheck= otherpkg->installed.depends;
  934. providecheck;
  935. providecheck= providecheck->next) {
  936. if (providecheck->type != dep_provides) continue;
  937. for (pdep= providecheck->list->ed->installed.depended;
  938. pdep;
  939. pdep= pdep->nextrev) {
  940. if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends &&
  941. pdep->up->type != dep_recommends)
  942. continue;
  943. if (depisok(pdep->up, &depprobwhy, NULL, 0))
  944. continue;
  945. varbufaddc(&depprobwhy,0);
  946. debug(dbg_veryverbose,"process_archive cannot disappear (provides %s): %s",
  947. providecheck->list->ed->name, depprobwhy.buf);
  948. goto break_from_both_loops_at_once;
  949. }
  950. }
  951. break_from_both_loops_at_once:;
  952. }
  953. otherpkg->clientdata->istobe= itb_normal;
  954. if (pdep) continue;
  955. printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"),
  956. otherpkg->name);
  957. debug(dbg_general, "process_archive disappearing %s",otherpkg->name);
  958. /* No, we're disappearing it. This is the wrong time to go and
  959. * run maintainer scripts and things, as we can't back out. But
  960. * what can we do ? It has to be run this late.
  961. */
  962. trig_activate_packageprocessing(otherpkg);
  963. maintainer_script_installed(otherpkg, POSTRMFILE,
  964. "post-removal script (for disappearance)",
  965. "disappear", pkg->name,
  966. versiondescribe(&pkg->available.version,
  967. vdew_nonambig),
  968. NULL);
  969. /* OK, now we delete all the stuff in the `info' directory .. */
  970. varbufreset(&fnvb);
  971. varbufaddstr(&fnvb,admindir);
  972. varbufaddstr(&fnvb,"/" INFODIR);
  973. infodirbaseused= fnvb.used;
  974. varbufaddc(&fnvb,0);
  975. dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
  976. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  977. debug(dbg_general, "process_archive disappear cleaning info directory");
  978. while ((de = readdir(dsd)) != NULL) {
  979. debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name);
  980. if (de->d_name[0] == '.') continue;
  981. p= strrchr(de->d_name,'.'); if (!p) continue;
  982. if (strlen(otherpkg->name) != (size_t)(p-de->d_name) ||
  983. strncmp(de->d_name,otherpkg->name,p-de->d_name)) continue;
  984. debug(dbg_stupidlyverbose, "process_archive info this pkg");
  985. fnvb.used= infodirbaseused;
  986. varbufaddstr(&fnvb,de->d_name);
  987. varbufaddc(&fnvb,0);
  988. if (unlink(fnvb.buf))
  989. ohshite(_("unable to delete disappearing control info file `%.250s'"),fnvb.buf);
  990. debug(dbg_scripts, "process_archive info unlinked %s",fnvb.buf);
  991. }
  992. pop_cleanup(ehflag_normaltidy); /* closedir */
  993. otherpkg->status= stat_notinstalled;
  994. otherpkg->want= want_purge;
  995. otherpkg->eflag= eflagv_ok;
  996. blankpackageperfile(&otherpkg->installed);
  997. otherpkg->clientdata->fileslistvalid= 0;
  998. modstatdb_note(otherpkg);
  999. } /* while (otherpkg= ... */
  1000. iterpkgend(it);
  1001. /* Delete files from any other packages' lists.
  1002. * We have to do this before we claim this package is in any
  1003. * sane kind of state, as otherwise we might delete by mistake
  1004. * a file that we overwrote, when we remove the package which
  1005. * had the version we overwrote. To prevent this we make
  1006. * sure that we don't claim this package is OK until we
  1007. * have claimed `ownership' of all its files.
  1008. */
  1009. for (cfile= newfileslist; cfile; cfile= cfile->next) {
  1010. if (!(cfile->namenode->flags & fnnf_elide_other_lists)) continue;
  1011. if (cfile->namenode->divert && cfile->namenode->divert->useinstead) {
  1012. divpkg= cfile->namenode->divert->pkg;
  1013. if (divpkg == pkg) {
  1014. debug(dbg_eachfile,
  1015. "process_archive not overwriting any `%s' (overriding, `%s')",
  1016. cfile->namenode->name, cfile->namenode->divert->useinstead->name);
  1017. continue;
  1018. } else {
  1019. debug(dbg_eachfile,
  1020. "process_archive looking for overwriting `%s' (overridden by %s)",
  1021. cfile->namenode->name, divpkg ? divpkg->name : "<local>");
  1022. }
  1023. } else {
  1024. divpkg = NULL;
  1025. debug(dbg_eachfile, "process_archive looking for overwriting `%s'",
  1026. cfile->namenode->name);
  1027. }
  1028. for (packageslump= cfile->namenode->packages;
  1029. packageslump;
  1030. packageslump= packageslump->more) {
  1031. for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) {
  1032. otherpkg= packageslump->pkgs[i];
  1033. debug(dbg_eachfiledetail, "process_archive ... found in %s\n",otherpkg->name);
  1034. /* If !fileslistvalid then it's one of the disappeared packages above
  1035. * and we don't bother with it here, clearly.
  1036. */
  1037. if (otherpkg == pkg || !otherpkg->clientdata->fileslistvalid) continue;
  1038. if (otherpkg == divpkg) {
  1039. debug(dbg_eachfiledetail, "process_archive ... diverted, skipping\n");
  1040. continue;
  1041. }
  1042. /* Found one. We delete remove the list entry for this file,
  1043. * (and any others in the same package) and then mark the package
  1044. * as requiring a reread.
  1045. */
  1046. write_filelist_except(otherpkg, otherpkg->clientdata->files, 1);
  1047. ensure_package_clientdata(otherpkg);
  1048. debug(dbg_veryverbose, "process_archive overwrote from %s",otherpkg->name);
  1049. }
  1050. }
  1051. }
  1052. /* Right, the package we've unpacked is now in a reasonable state.
  1053. * The only thing that we have left to do with it is remove
  1054. * backup files, and we can leave the user to fix that if and when
  1055. * it happens (we leave the reinstall required flag, of course).
  1056. */
  1057. pkg->status= stat_unpacked;
  1058. modstatdb_note(pkg);
  1059. /* Now we delete all the backup files that we made when
  1060. * extracting the archive - except for files listed as conffiles
  1061. * in the new package.
  1062. * This time we count it as an error if something goes wrong.
  1063. *
  1064. * Note that we don't ever delete things that were in the old
  1065. * package as a conffile and don't appear at all in the new.
  1066. * They stay recorded as obsolete conffiles and will eventually
  1067. * (if not taken over by another package) be forgotten.
  1068. */
  1069. for (cfile= newfileslist; cfile; cfile= cfile->next) {
  1070. if (cfile->namenode->flags & fnnf_new_conff) continue;
  1071. fnametmpvb.used= fnameidlu;
  1072. varbufaddstr(&fnametmpvb,namenodetouse(cfile->namenode,pkg)->name);
  1073. varbufaddstr(&fnametmpvb,DPKGTEMPEXT);
  1074. varbufaddc(&fnametmpvb,0);
  1075. ensure_pathname_nonexisting(fnametmpvb.buf);
  1076. }
  1077. /* OK, we're now fully done with the main package.
  1078. * This is quite a nice state, so we don't unwind past here.
  1079. */
  1080. pkg->eflag= eflagv_ok;
  1081. modstatdb_note(pkg);
  1082. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  1083. /* Only the removal of the conflictor left to do.
  1084. * The files list for the conflictor is still a little inconsistent in-core,
  1085. * as we have not yet updated the filename->packages mappings; however,
  1086. * the package->filenames mapping is
  1087. */
  1088. for (i = 0 ; i < cflict_index ; i++) {
  1089. /* We need to have the most up-to-date info about which files are what ... */
  1090. ensure_allinstfiles_available();
  1091. removal_bulk(conflictor[i]);
  1092. }
  1093. if (cipaction->arg == act_install) add_to_queue(pkg);
  1094. }