processarc.c 46 KB

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