processarc.c 46 KB

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