processarc.c 45 KB

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