processarc.c 46 KB

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