processarc.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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 = NULL, *reasmbuf = NULL;
  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, NULL, 0, 1, (void *)reasmbuf);
  104. c1= m_fork();
  105. if (!c1) {
  106. execlp(SPLITTER, SPLITTER, "-Qao", reasmbuf, filename, NULL);
  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, NULL, 0, 2, (void *)cidir, (void *)cidirrest);
  169. c1= m_fork();
  170. if (!c1) {
  171. cidirrest[-1]= 0;
  172. execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL);
  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 = NULL;
  182. pkg->files->name = pkg->files->msdosname = pkg->files->md5sum = NULL;
  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 = NULL;
  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_breaks:
  222. /* Look for things we break. */
  223. check_breaks(dsearch, pkg, pfilename);
  224. break;
  225. case dep_provides:
  226. /* Look for things that conflict with what we provide. */
  227. if (dsearch->list->ed->installed.valid) {
  228. for (psearch= dsearch->list->ed->installed.depended;
  229. psearch;
  230. psearch= psearch->nextrev) {
  231. if (psearch->up->type != dep_conflicts) continue;
  232. check_conflict(psearch->up, pkg, pfilename);
  233. }
  234. }
  235. break;
  236. case dep_suggests:
  237. case dep_recommends:
  238. case dep_depends:
  239. case dep_replaces:
  240. case dep_enhances:
  241. /* Ignore these here. */
  242. break;
  243. case dep_predepends:
  244. if (!depisok(dsearch, &depprobwhy, NULL, 1)) {
  245. varbufaddc(&depprobwhy,0);
  246. fprintf(stderr, _("dpkg: regarding %s containing %s, pre-dependency problem:\n%s"),
  247. pfilename, pkg->name, depprobwhy.buf);
  248. if (!force_depends(dsearch->list))
  249. ohshit(_("pre-dependency problem - not installing %.250s"),pkg->name);
  250. fprintf(stderr, _("dpkg: warning - ignoring pre-dependency problem !\n"));
  251. }
  252. }
  253. }
  254. /* Look for things that conflict with us. */
  255. for (psearch= pkg->installed.depended; psearch; psearch= psearch->nextrev) {
  256. if (psearch->up->type != dep_conflicts) continue;
  257. check_conflict(psearch->up, pkg, pfilename);
  258. }
  259. ensure_allinstfiles_available();
  260. filesdbinit();
  261. trig_file_interests_ensure();
  262. if (pkg->status != stat_notinstalled && pkg->status != stat_configfiles) {
  263. printf(_("Preparing to replace %s %s (using %s) ...\n"),
  264. pkg->name,
  265. versiondescribe(&pkg->installed.version,vdew_nonambig),
  266. pfilename);
  267. log_action("upgrade", pkg);
  268. } else {
  269. printf(_("Unpacking %s (from %s) ...\n"),pkg->name,pfilename);
  270. log_action("install", pkg);
  271. }
  272. if (f_noact) {
  273. pop_cleanup(ehflag_normaltidy);
  274. return;
  275. }
  276. /*
  277. * OK, we're going ahead.
  278. */
  279. trig_activate_packageprocessing(pkg);
  280. strcpy(cidirrest, TRIGGERSCIFILE);
  281. trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg);
  282. /* Read the conffiles, and copy the hashes across. */
  283. newconffiles = NULL;
  284. newconffileslastp = &newconffiles;
  285. push_cleanup(cu_fileslist, ~0, NULL, 0, 0);
  286. strcpy(cidirrest,CONFFILESFILE);
  287. conff= fopen(cidir,"r");
  288. if (conff) {
  289. push_cleanup(cu_closefile, ehflag_bombout, NULL, 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 = NULL;
  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_installed);
  361. debug(dbg_general,"process_archive oldversionstatus=%s",
  362. statusstrings[oldversionstatus]);
  363. if (oldversionstatus == stat_halfconfigured ||
  364. oldversionstatus == stat_triggersawaited ||
  365. oldversionstatus == stat_triggerspending ||
  366. oldversionstatus == stat_installed) {
  367. pkg->eflag |= eflagf_reinstreq;
  368. pkg->status= stat_halfconfigured;
  369. modstatdb_note(pkg);
  370. push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg);
  371. maintainer_script_alternative(pkg, PRERMFILE, "pre-removal", cidir, cidirrest,
  372. "upgrade", "failed-upgrade");
  373. pkg->status= stat_unpacked;
  374. oldversionstatus= stat_unpacked;
  375. modstatdb_note(pkg);
  376. }
  377. for (deconpil= deconfigure; deconpil; deconpil= deconpil->next) {
  378. struct pkginfo *removing= deconpil->xinfo;
  379. if (removing)
  380. printf(_("De-configuring %s, to allow removal of %s ...\n"),
  381. deconpil->pkg->name, removing->name);
  382. else
  383. printf(_("De-configuring %s ...\n"), deconpil->pkg->name);
  384. trig_activate_packageprocessing(deconpil->pkg);
  385. deconpil->pkg->status= stat_halfconfigured;
  386. modstatdb_note(deconpil->pkg);
  387. /* This means that we *either* go and run postinst abort-deconfigure,
  388. * *or* queue the package for later configure processing, depending
  389. * on which error cleanup route gets taken.
  390. */
  391. push_cleanup(cu_prermdeconfigure, ~ehflag_normaltidy,
  392. ok_prermdeconfigure, ehflag_normaltidy,
  393. 3, (void*)deconpil->pkg, (void*)removing, (void*)pkg);
  394. if (removing) {
  395. maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal",
  396. "deconfigure", "in-favour", pkg->name,
  397. versiondescribe(&pkg->available.version,
  398. vdew_nonambig),
  399. "removing", removing->name,
  400. versiondescribe(&removing->installed.version,
  401. vdew_nonambig),
  402. NULL);
  403. } else {
  404. maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal",
  405. "deconfigure", "in-favour", pkg->name,
  406. versiondescribe(&pkg->available.version,
  407. vdew_nonambig),
  408. NULL);
  409. }
  410. }
  411. for (i = 0 ; i < cflict_index; i++) {
  412. if (!(conflictor[i]->status == stat_halfconfigured ||
  413. conflictor[i]->status == stat_triggersawaited ||
  414. conflictor[i]->status == stat_triggerspending ||
  415. conflictor[i]->status == stat_installed)) continue;
  416. trig_activate_packageprocessing(conflictor[i]);
  417. conflictor[i]->status= stat_halfconfigured;
  418. modstatdb_note(conflictor[i]);
  419. push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, NULL, 0,
  420. 2,(void*)conflictor[i],(void*)pkg);
  421. maintainer_script_installed(conflictor[i], PRERMFILE, "pre-removal",
  422. "remove", "in-favour", pkg->name,
  423. versiondescribe(&pkg->available.version,
  424. vdew_nonambig),
  425. NULL);
  426. conflictor[i]->status= stat_halfinstalled;
  427. modstatdb_note(conflictor[i]);
  428. }
  429. pkg->eflag |= eflagf_reinstreq;
  430. if (pkg->status == stat_notinstalled)
  431. pkg->installed.version= pkg->available.version;
  432. pkg->status= stat_halfinstalled;
  433. modstatdb_note(pkg);
  434. if (oldversionstatus == stat_notinstalled) {
  435. push_cleanup(cu_preinstverynew, ~ehflag_normaltidy, NULL, 0,
  436. 3,(void*)pkg,(void*)cidir,(void*)cidirrest);
  437. maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
  438. "install", NULL);
  439. } else if (oldversionstatus == stat_configfiles) {
  440. push_cleanup(cu_preinstnew, ~ehflag_normaltidy, NULL, 0,
  441. 3,(void*)pkg,(void*)cidir,(void*)cidirrest);
  442. maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
  443. "install", versiondescribe(&pkg->installed.version,
  444. vdew_nonambig),
  445. NULL);
  446. } else {
  447. push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0,
  448. 4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus);
  449. maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
  450. "upgrade", versiondescribe(&pkg->installed.version,
  451. vdew_nonambig),
  452. NULL);
  453. printf(_("Unpacking replacement %.250s ...\n"),pkg->name);
  454. }
  455. /*
  456. * Now we unpack the archive, backing things up as we go.
  457. * For each file, we check to see if it already exists.
  458. * There are several possibilities:
  459. * + We are trying to install a non-directory ...
  460. * - It doesn't exist. In this case we simply extract it.
  461. * - It is a plain file, device, symlink, &c. We do an `atomic
  462. * overwrite' using link() and rename(), but leave a backup copy.
  463. * Later, when we delete the backup, we remove it from any other
  464. * packages' lists.
  465. * - It is a directory. In this case it depends on whether we're
  466. * trying to install a symlink or something else.
  467. * = If we're not trying to install a symlink we move the directory
  468. * aside and extract the node. Later, when we recursively remove
  469. * the backed-up directory, we remove it from any other packages'
  470. * lists.
  471. * = If we are trying to install a symlink we do nothing - ie,
  472. * dpkg will never replace a directory tree with a symlink. This
  473. * is to avoid embarrassing effects such as replacing a directory
  474. * tree with a link to a link to the original directory tree.
  475. * + We are trying to install a directory ...
  476. * - It doesn't exist. We create it with the appropriate modes.
  477. * - It exists as a directory or a symlink to one. We do nothing.
  478. * - It is a plain file or a symlink (other than to a directory).
  479. * We move it aside and create the directory. Later, when we
  480. * delete the backup, we remove it from any other packages' lists.
  481. *
  482. * Install non-dir Install symlink Install dir
  483. * Exists not X X X
  484. * File/node/symlink LXR LXR BXR
  485. * Directory BXR - -
  486. *
  487. * X: extract file/node/link/directory
  488. * LX: atomic overwrite leaving backup
  489. * B: ordinary backup
  490. * R: later remove from other packages' lists
  491. * -: do nothing
  492. *
  493. * After we've done this we go through the remaining things in the
  494. * lists of packages we're trying to remove (including the old
  495. * version of the current package). This happens in reverse order,
  496. * so that we process files before the directories (or symlinks-to-
  497. * directories) containing them.
  498. * + If the thing is a conffile then we leave it alone for the purge
  499. * operation.
  500. * + Otherwise, there are several possibilities too:
  501. * - The listed thing does not exist. We ignore it.
  502. * - The listed thing is a directory or a symlink to a directory.
  503. * We delete it only if it isn't listed in any other package.
  504. * - The listed thing is not a directory, but was part of the package
  505. * that was upgraded, we check to make sure the files aren't the
  506. * same ones from the old package by checking dev/inode
  507. * - The listed thing is not a directory or a symlink to one (ie,
  508. * it's a plain file, device, pipe, &c, or a symlink to one, or a
  509. * dangling symlink). We delete it.
  510. * The removed packages' list becomes empty (of course, the new
  511. * version of the package we're installing will have a new list,
  512. * which replaces the old version's list).
  513. *
  514. * If at any stage we remove a file from a package's list, and the
  515. * package isn't one we're already processing, and the package's
  516. * list becomes empty as a result, we `vanish' the package. This
  517. * means that we run its postrm with the `disappear' argument, and
  518. * put the package in the `not-installed' state. If it had any
  519. * conffiles, their hashes and ownership will have been transferred
  520. * already, so we just ignore those and forget about them from the
  521. * point of view of the disappearing package.
  522. *
  523. * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the
  524. * files get replaced `as we go'.
  525. */
  526. m_pipe(p1);
  527. push_cleanup(cu_closepipe, ehflag_bombout, NULL, 0, 1, (void *)&p1[0]);
  528. c1= m_fork();
  529. if (!c1) {
  530. m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
  531. execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL);
  532. ohshite(_("unable to exec dpkg-deb to get filesystem archive"));
  533. }
  534. close(p1[1]);
  535. p1[1] = -1;
  536. newfileslist = NULL;
  537. tc.newfilesp = &newfileslist;
  538. push_cleanup(cu_fileslist, ~0, NULL, 0, 0);
  539. tc.pkg= pkg;
  540. tc.backendpipe= p1[0];
  541. r= TarExtractor((void*)&tc, &tf);
  542. if (r) {
  543. if (errno) {
  544. ohshite(_("error reading dpkg-deb tar output"));
  545. } else {
  546. ohshit(_("corrupted filesystem tarfile - corrupted package archive"));
  547. }
  548. }
  549. fd_null_copy(p1[0], -1, _("dpkg-deb: zap possible trailing zeros"));
  550. close(p1[0]);
  551. p1[0] = -1;
  552. waitsubproc(c1,BACKEND " --fsys-tarfile",PROCPIPE);
  553. if (oldversionstatus == stat_halfinstalled || oldversionstatus == stat_unpacked) {
  554. /* Packages that were in `installed' and `postinstfailed' have been reduced
  555. * to `unpacked' by now, by the running of the prerm script.
  556. */
  557. pkg->status= stat_halfinstalled;
  558. modstatdb_note(pkg);
  559. push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg);
  560. maintainer_script_alternative(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
  561. "upgrade", "failed-upgrade");
  562. }
  563. /* If anything goes wrong while tidying up it's a bit late to do
  564. * anything about it. However, we don't install the new status
  565. * info yet, so that a future dpkg installation will put everything
  566. * right (we hope).
  567. *
  568. * If something does go wrong later the `conflictor' package will be
  569. * left in the `removal_failed' state. Removing or installing it
  570. * will be impossible if it was required because of the conflict with
  571. * the package we're installing now and (presumably) the dependency
  572. * by other packages. This means that the files it contains in
  573. * common with this package will hang around until we successfully
  574. * get this package installed, after which point we can trust the
  575. * conflicting package's file list, which will have been updated to
  576. * remove any files in this package.
  577. */
  578. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  579. /* Now we delete all the files that were in the old version of
  580. * the package only, except (old or new) conffiles, which we leave
  581. * alone.
  582. */
  583. reversefilelist_init(&rlistit,pkg->clientdata->files);
  584. while ((namenode= reversefilelist_next(&rlistit))) {
  585. if ((namenode->flags & fnnf_new_conff) ||
  586. (namenode->flags & fnnf_new_inarchive))
  587. continue;
  588. fnamevb.used= fnameidlu;
  589. varbufaddstr(&fnamevb, namenodetouse(namenode,pkg)->name);
  590. varbufaddc(&fnamevb,0);
  591. if (!stat(namenode->name,&stab) && S_ISDIR(stab.st_mode)) {
  592. debug(dbg_eachfiledetail, "process_archive: %s is a directory",
  593. namenode->name);
  594. if (isdirectoryinuse(namenode,pkg)) continue;
  595. }
  596. if (lstat(fnamevb.buf, &oldfs)) {
  597. if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
  598. fprintf(stderr,
  599. _("dpkg: warning - could not stat old file `%.250s'"
  600. " so not deleting it: %s"),
  601. fnamevb.buf, strerror(errno));
  602. continue;
  603. }
  604. if (S_ISDIR(oldfs.st_mode)) {
  605. if (rmdir(fnamevb.buf)) {
  606. fprintf(stderr,
  607. _("dpkg: warning - unable to delete old directory"
  608. " `%.250s': %s\n"), namenode->name, strerror(errno));
  609. } else if ((namenode->flags & fnnf_old_conff)) {
  610. fprintf(stderr,
  611. _("dpkg: warning - old conffile `%.250s' was an empty"
  612. " directory (and has now been deleted)\n"),
  613. namenode->name);
  614. }
  615. } else {
  616. /* Ok, it's an old file, but is it really not in the new package?
  617. * It might be known by a different name because of symlinks.
  618. *
  619. * We need to check to make sure, so we stat the file, then compare
  620. * it to the new list. If we find a dev/inode match, we assume they
  621. * are the same file, and leave it alone. NOTE: we don't check in
  622. * other packages for sanity reasons (we don't want to stat _all_
  623. * the files on the system).
  624. *
  625. * We run down the list of _new_ files in this package. This keeps
  626. * the process a little leaner. We are only worried about new ones
  627. * since ones that stayed the same don't really apply here.
  628. */
  629. struct fileinlist *sameas = NULL;
  630. /* If we can't stat the old or new file, or it's a directory,
  631. * we leave it up to the normal code
  632. */
  633. debug(dbg_eachfile, "process_archive: checking %s for same files on "
  634. "upgrade/downgrade", fnamevb.buf);
  635. for (cfile= newfileslist; cfile; cfile= cfile->next) {
  636. if (!cfile->namenode->filestat) {
  637. cfile->namenode->filestat= nfmalloc(sizeof(struct stat));
  638. if (lstat(cfile->namenode->name, cfile->namenode->filestat)) {
  639. if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
  640. ohshite(_("unable to stat other new file `%.250s'"),
  641. cfile->namenode->name);
  642. memset(cfile->namenode->filestat, 0,
  643. sizeof(*cfile->namenode->filestat));
  644. continue;
  645. }
  646. }
  647. if (!cfile->namenode->filestat->st_mode) continue;
  648. if (oldfs.st_dev == cfile->namenode->filestat->st_dev &&
  649. oldfs.st_ino == cfile->namenode->filestat->st_ino) {
  650. if (sameas)
  651. fprintf(stderr, _("dpkg: warning - old file `%.250s' is the same"
  652. " as several new files! (both `%.250s' and `%.250s')\n"),
  653. fnamevb.buf,
  654. sameas->namenode->name, cfile->namenode->name);
  655. sameas= cfile;
  656. debug(dbg_eachfile, "process_archive: not removing %s,"
  657. " since it matches %s", fnamevb.buf, cfile->namenode->name);
  658. }
  659. }
  660. if ((namenode->flags & fnnf_old_conff)) {
  661. if (sameas) {
  662. if (sameas->namenode->flags & fnnf_new_conff) {
  663. if (!strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG)) {
  664. sameas->namenode->oldhash= namenode->oldhash;
  665. debug(dbg_eachfile, "process_archive: old conff %s"
  666. " is same as new conff %s, copying hash",
  667. namenode->name, sameas->namenode->name);
  668. } else {
  669. debug(dbg_eachfile, "process_archive: old conff %s"
  670. " is same as new conff %s but latter already has hash",
  671. namenode->name, sameas->namenode->name);
  672. }
  673. }
  674. } else {
  675. debug(dbg_eachfile, "process_archive: old conff %s"
  676. " is disappearing", namenode->name);
  677. namenode->flags |= fnnf_obs_conff;
  678. newconff_append(&newconffileslastp, namenode);
  679. addfiletolist(&tc, namenode);
  680. }
  681. continue;
  682. }
  683. if (sameas)
  684. continue;
  685. failed= N_("delete");
  686. if (chmodsafe_unlink_statted(fnamevb.buf, &oldfs, &failed)) {
  687. char mbuf[250];
  688. snprintf(mbuf, sizeof(mbuf),
  689. N_("dpkg: warning - unable to %s old file `%%.250s': %%s\n"),
  690. failed);
  691. fprintf(stderr, _(mbuf), namenode->name, strerror(errno));
  692. }
  693. } /* !S_ISDIR */
  694. }
  695. /* OK, now we can write the updated files-in-this package list,
  696. * since we've done away (hopefully) with all the old junk.
  697. */
  698. write_filelist_except(pkg,newfileslist,0);
  699. /* Trigger interests may have changed.
  700. * Firstly we go through the old list of interests deleting them.
  701. * Then we go through the new list adding them.
  702. */
  703. strcpy(cidirrest, TRIGGERSCIFILE);
  704. trig_parse_ci(pkgadminfile(pkg, TRIGGERSCIFILE),
  705. trig_cicb_interest_delete, NULL, pkg);
  706. trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg);
  707. trig_file_interests_save();
  708. /* We also install the new maintainer scripts, and any other
  709. * cruft that may have come along with the package. First
  710. * we go through the existing scripts replacing or removing
  711. * them as appropriate; then we go through the new scripts
  712. * (any that are left) and install them.
  713. */
  714. debug(dbg_general, "process_archive updating info directory");
  715. varbufreset(&infofnvb);
  716. varbufaddstr(&infofnvb,admindir);
  717. varbufaddstr(&infofnvb,"/" INFODIR "/");
  718. infodirlen= infofnvb.used;
  719. varbufaddc(&infofnvb,0);
  720. dsd= opendir(infofnvb.buf);
  721. if (!dsd) ohshite(_("cannot read info directory"));
  722. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  723. while ((de = readdir(dsd)) != NULL) {
  724. debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name);
  725. if (de->d_name[0] == '.') continue; /* ignore dotfiles, including `.' and `..' */
  726. p= strrchr(de->d_name,'.'); if (!p) continue; /* ignore anything odd */
  727. if (strlen(pkg->name) != (size_t)(p-de->d_name) ||
  728. strncmp(de->d_name,pkg->name,p-de->d_name)) continue;
  729. debug(dbg_stupidlyverbose, "process_archive info this pkg");
  730. /* Right do we have one ? */
  731. p++; /* skip past the full stop */
  732. if (!strcmp(p,LISTFILE)) continue; /* We do the list separately */
  733. if (strlen(p) > MAXCONTROLFILENAME)
  734. ohshit(_("old version of package has overly-long info file name starting `%.250s'"),
  735. de->d_name);
  736. infofnvb.used= infodirlen;
  737. varbufaddstr(&infofnvb,de->d_name);
  738. varbufaddc(&infofnvb,0);
  739. strcpy(cidirrest,p);
  740. if (!rename(cidir,infofnvb.buf)) {
  741. debug(dbg_scripts, "process_archive info installed %s as %s",
  742. cidir, infofnvb.buf);
  743. } else if (errno == ENOENT) {
  744. /* Right, no new version. */
  745. if (unlink(infofnvb.buf))
  746. ohshite(_("unable to remove obsolete info file `%.250s'"),infofnvb.buf);
  747. debug(dbg_scripts, "process_archive info unlinked %s",infofnvb.buf);
  748. } else {
  749. ohshite(_("unable to install (supposed) new info file `%.250s'"),cidir);
  750. }
  751. }
  752. pop_cleanup(ehflag_normaltidy); /* closedir */
  753. *cidirrest= 0; /* the directory itself */
  754. dsd= opendir(cidir);
  755. if (!dsd) ohshite(_("unable to open temp control directory"));
  756. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  757. while ((de= readdir(dsd))) {
  758. if (strchr(de->d_name,'.')) {
  759. debug(dbg_scripts,"process_archive tmp.ci script/file `%s' contains dot",
  760. de->d_name);
  761. continue;
  762. }
  763. if (strlen(de->d_name) > MAXCONTROLFILENAME)
  764. ohshit(_("package contains overly-long control info file name (starting `%.50s')"),
  765. de->d_name);
  766. strcpy(cidirrest,de->d_name);
  767. /* First we check it's not a directory. */
  768. if (!rmdir(cidir))
  769. ohshit(_("package control info contained directory `%.250s'"),cidir);
  770. else if (errno != ENOTDIR)
  771. ohshite(_("package control info rmdir of `%.250s' didn't say not a dir"),de->d_name);
  772. if (!strcmp(de->d_name,CONTROLFILE)) {
  773. debug(dbg_scripts,"process_archive tmp.ci script/file `%s' is control",cidir);
  774. continue; /* ignore the control file */
  775. }
  776. if (!strcmp(de->d_name,LISTFILE)) {
  777. fprintf(stderr, _("dpkg: warning - package %s"
  778. " contained list as info file"), pkg->name);
  779. continue;
  780. }
  781. /* Right, install it */
  782. newinfofilename= pkgadminfile(pkg,de->d_name);
  783. if (rename(cidir,newinfofilename))
  784. ohshite(_("unable to install new info file `%.250s' as `%.250s'"),
  785. cidir,newinfofilename);
  786. debug(dbg_scripts,"process_archive tmp.ci script/file `%s' installed as `%s'",
  787. cidir, newinfofilename);
  788. }
  789. pop_cleanup(ehflag_normaltidy); /* closedir */
  790. /* Update the status database.
  791. * This involves copying each field across from the `available'
  792. * to the `installed' half of the pkg structure.
  793. * For some of the fields we have to do a complicated construction
  794. * operation; for others we can just copy the value.
  795. * We tackle the fields in the order they appear, so that
  796. * we don't miss any out :-).
  797. * At least we don't have to copy any strings that are referred
  798. * to, because these are never modified and never freed.
  799. */
  800. /* The dependencies are the most difficult. We have to build
  801. * a whole new forward dependency tree. At least the reverse
  802. * links (linking our deppossi's into the reverse chains)
  803. * can be done by copy_dependency_links.
  804. */
  805. newdeplist = NULL;
  806. newdeplistlastp = &newdeplist;
  807. for (dep= pkg->available.depends; dep; dep= dep->next) {
  808. newdep= nfmalloc(sizeof(struct dependency));
  809. newdep->up= pkg;
  810. newdep->next = NULL;
  811. newdep->list = NULL;
  812. newpossilastp = &newdep->list;
  813. for (possi= dep->list; possi; possi= possi->next) {
  814. newpossi= nfmalloc(sizeof(struct deppossi));
  815. newpossi->up= newdep;
  816. newpossi->ed= possi->ed;
  817. newpossi->next = NULL;
  818. newpossi->nextrev = newpossi->backrev = NULL;
  819. newpossi->verrel= possi->verrel;
  820. if (possi->verrel != dvr_none)
  821. newpossi->version= possi->version;
  822. else
  823. blankversion(&newpossi->version);
  824. newpossi->cyclebreak= 0;
  825. *newpossilastp= newpossi;
  826. newpossilastp= &newpossi->next;
  827. }
  828. newdep->type= dep->type;
  829. *newdeplistlastp= newdep;
  830. newdeplistlastp= &newdep->next;
  831. }
  832. /* Right, now we've replicated the forward tree, we
  833. * get copy_dependency_links to remove all the old dependency
  834. * structures from the reverse links and add the new dependency
  835. * structures in instead. It also copies the new dependency
  836. * structure pointer for this package into the right field.
  837. */
  838. copy_dependency_links(pkg,&pkg->installed.depends,newdeplist,0);
  839. /* The `depended' pointer in the structure doesn't represent anything
  840. * that is actually specified by this package - it's there so we
  841. * can find out what other packages refer to this one. So,
  842. * we don't copy it. We go straight on to copy the text fields.
  843. */
  844. pkg->installed.essential= pkg->available.essential;
  845. pkg->installed.description= pkg->available.description;
  846. pkg->installed.maintainer= pkg->available.maintainer;
  847. pkg->installed.source= pkg->available.source;
  848. pkg->installed.architecture= pkg->available.architecture;
  849. pkg->installed.installedsize= pkg->available.installedsize;
  850. pkg->installed.version= pkg->available.version;
  851. pkg->installed.origin = pkg->available.origin;
  852. pkg->installed.bugs = pkg->available.bugs;
  853. /* We have to generate our own conffiles structure. */
  854. pkg->installed.conffiles = NULL;
  855. iconffileslastp = &pkg->installed.conffiles;
  856. for (cfile= newconffiles; cfile; cfile= cfile->next) {
  857. newiconff= nfmalloc(sizeof(struct conffile));
  858. newiconff->next = NULL;
  859. newiconff->name= nfstrsave(cfile->namenode->name);
  860. newiconff->hash= nfstrsave(cfile->namenode->oldhash);
  861. newiconff->obsolete= !!(cfile->namenode->flags & fnnf_obs_conff);
  862. *iconffileslastp= newiconff;
  863. iconffileslastp= &newiconff->next;
  864. }
  865. /* We can just copy the arbitrary fields list, because it is
  866. * never even rearragned. Phew !
  867. */
  868. pkg->installed.arbs= pkg->available.arbs;
  869. /* Check for disappearing packages:
  870. * We go through all the packages on the system looking for ones
  871. * whose files are entirely part of the one we've just unpacked
  872. * (and which actually *have* some files!).
  873. *
  874. * Any that we find are removed - we run the postrm with `disappear'
  875. * as an argument, and remove their info/... files and status info.
  876. * Conffiles are ignored (the new package had better do something
  877. * with them !).
  878. */
  879. it= iterpkgstart();
  880. while ((otherpkg = iterpkgnext(it)) != NULL) {
  881. ensure_package_clientdata(otherpkg);
  882. if (otherpkg == pkg ||
  883. otherpkg->status == stat_notinstalled ||
  884. otherpkg->status == stat_configfiles ||
  885. otherpkg->clientdata->istobe == itb_remove ||
  886. !otherpkg->clientdata->files) continue;
  887. debug(dbg_veryverbose, "process_archive checking disappearance %s",otherpkg->name);
  888. assert(otherpkg->clientdata->istobe == itb_normal ||
  889. otherpkg->clientdata->istobe == itb_deconfigure);
  890. for (cfile= otherpkg->clientdata->files;
  891. cfile && !strcmp(cfile->namenode->name,"/.");
  892. cfile= cfile->next);
  893. if (!cfile) {
  894. debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear");
  895. continue;
  896. }
  897. for (cfile= otherpkg->clientdata->files;
  898. cfile && !filesavespackage(cfile,otherpkg,pkg);
  899. cfile= cfile->next);
  900. if (cfile) continue;
  901. /* So dependency things will give right answers ... */
  902. otherpkg->clientdata->istobe= itb_remove;
  903. debug(dbg_veryverbose, "process_archive disappear checking dependencies");
  904. for (pdep= otherpkg->installed.depended;
  905. pdep;
  906. pdep= pdep->nextrev) {
  907. if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends &&
  908. pdep->up->type != dep_recommends) continue;
  909. if (depisok(pdep->up, &depprobwhy, NULL, 0))
  910. continue;
  911. varbufaddc(&depprobwhy,0);
  912. debug(dbg_veryverbose,"process_archive cannot disappear: %s",depprobwhy.buf);
  913. break;
  914. }
  915. if (!pdep) {
  916. /* If we haven't found a reason not to yet, let's look some more. */
  917. for (providecheck= otherpkg->installed.depends;
  918. providecheck;
  919. providecheck= providecheck->next) {
  920. if (providecheck->type != dep_provides) continue;
  921. for (pdep= providecheck->list->ed->installed.depended;
  922. pdep;
  923. pdep= pdep->nextrev) {
  924. if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends &&
  925. pdep->up->type != dep_recommends)
  926. continue;
  927. if (depisok(pdep->up, &depprobwhy, NULL, 0))
  928. continue;
  929. varbufaddc(&depprobwhy,0);
  930. debug(dbg_veryverbose,"process_archive cannot disappear (provides %s): %s",
  931. providecheck->list->ed->name, depprobwhy.buf);
  932. goto break_from_both_loops_at_once;
  933. }
  934. }
  935. break_from_both_loops_at_once:;
  936. }
  937. otherpkg->clientdata->istobe= itb_normal;
  938. if (pdep) continue;
  939. printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"),
  940. otherpkg->name);
  941. debug(dbg_general, "process_archive disappearing %s",otherpkg->name);
  942. /* No, we're disappearing it. This is the wrong time to go and
  943. * run maintainer scripts and things, as we can't back out. But
  944. * what can we do ? It has to be run this late.
  945. */
  946. trig_activate_packageprocessing(otherpkg);
  947. maintainer_script_installed(otherpkg, POSTRMFILE,
  948. "post-removal script (for disappearance)",
  949. "disappear", pkg->name,
  950. versiondescribe(&pkg->available.version,
  951. vdew_nonambig),
  952. NULL);
  953. /* OK, now we delete all the stuff in the `info' directory .. */
  954. varbufreset(&fnvb);
  955. varbufaddstr(&fnvb,admindir);
  956. varbufaddstr(&fnvb,"/" INFODIR);
  957. infodirbaseused= fnvb.used;
  958. varbufaddc(&fnvb,0);
  959. dsd= opendir(fnvb.buf); if (!dsd) ohshite(_("cannot read info directory"));
  960. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)dsd);
  961. debug(dbg_general, "process_archive disappear cleaning info directory");
  962. while ((de = readdir(dsd)) != NULL) {
  963. debug(dbg_veryverbose, "process_archive info file `%s'", de->d_name);
  964. if (de->d_name[0] == '.') continue;
  965. p= strrchr(de->d_name,'.'); if (!p) continue;
  966. if (strlen(otherpkg->name) != (size_t)(p-de->d_name) ||
  967. strncmp(de->d_name,otherpkg->name,p-de->d_name)) continue;
  968. debug(dbg_stupidlyverbose, "process_archive info this pkg");
  969. fnvb.used= infodirbaseused;
  970. varbufaddstr(&fnvb,de->d_name);
  971. varbufaddc(&fnvb,0);
  972. if (unlink(fnvb.buf))
  973. ohshite(_("unable to delete disappearing control info file `%.250s'"),fnvb.buf);
  974. debug(dbg_scripts, "process_archive info unlinked %s",fnvb.buf);
  975. }
  976. pop_cleanup(ehflag_normaltidy); /* closedir */
  977. otherpkg->status= stat_notinstalled;
  978. otherpkg->want= want_purge;
  979. otherpkg->eflag= eflagv_ok;
  980. otherpkg->installed.depends = NULL;
  981. otherpkg->installed.essential= 0;
  982. otherpkg->installed.description = otherpkg->installed.maintainer = NULL;
  983. otherpkg->installed.installedsize = otherpkg->installed.source = NULL;
  984. otherpkg->installed.origin = otherpkg->installed.bugs = NULL;
  985. otherpkg->installed.architecture = NULL;
  986. otherpkg->installed.conffiles = NULL;
  987. blankversion(&otherpkg->installed.version);
  988. otherpkg->installed.arbs = NULL;
  989. otherpkg->clientdata->fileslistvalid= 0;
  990. modstatdb_note(otherpkg);
  991. } /* while (otherpkg= ... */
  992. iterpkgend(it);
  993. /* Delete files from any other packages' lists.
  994. * We have to do this before we claim this package is in any
  995. * sane kind of state, as otherwise we might delete by mistake
  996. * a file that we overwrote, when we remove the package which
  997. * had the version we overwrote. To prevent this we make
  998. * sure that we don't claim this package is OK until we
  999. * have claimed `ownership' of all its files.
  1000. */
  1001. for (cfile= newfileslist; cfile; cfile= cfile->next) {
  1002. if (!(cfile->namenode->flags & fnnf_elide_other_lists)) continue;
  1003. if (cfile->namenode->divert && cfile->namenode->divert->useinstead) {
  1004. divpkg= cfile->namenode->divert->pkg;
  1005. if (divpkg == pkg) {
  1006. debug(dbg_eachfile,
  1007. "process_archive not overwriting any `%s' (overriding, `%s')",
  1008. cfile->namenode->name, cfile->namenode->divert->useinstead->name);
  1009. continue;
  1010. } else {
  1011. debug(dbg_eachfile,
  1012. "process_archive looking for overwriting `%s' (overridden by %s)",
  1013. cfile->namenode->name, divpkg ? divpkg->name : "<local>");
  1014. }
  1015. } else {
  1016. divpkg = NULL;
  1017. debug(dbg_eachfile, "process_archive looking for overwriting `%s'",
  1018. cfile->namenode->name);
  1019. }
  1020. for (packageslump= cfile->namenode->packages;
  1021. packageslump;
  1022. packageslump= packageslump->more) {
  1023. for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) {
  1024. otherpkg= packageslump->pkgs[i];
  1025. debug(dbg_eachfiledetail, "process_archive ... found in %s\n",otherpkg->name);
  1026. /* If !fileslistvalid then it's one of the disappeared packages above
  1027. * and we don't bother with it here, clearly.
  1028. */
  1029. if (otherpkg == pkg || !otherpkg->clientdata->fileslistvalid) continue;
  1030. if (otherpkg == divpkg) {
  1031. debug(dbg_eachfiledetail, "process_archive ... diverted, skipping\n");
  1032. continue;
  1033. }
  1034. /* Found one. We delete remove the list entry for this file,
  1035. * (and any others in the same package) and then mark the package
  1036. * as requiring a reread.
  1037. */
  1038. write_filelist_except(otherpkg, otherpkg->clientdata->files, 1);
  1039. ensure_package_clientdata(otherpkg);
  1040. debug(dbg_veryverbose, "process_archive overwrote from %s",otherpkg->name);
  1041. }
  1042. }
  1043. }
  1044. /* Right, the package we've unpacked is now in a reasonable state.
  1045. * The only thing that we have left to do with it is remove
  1046. * backup files, and we can leave the user to fix that if and when
  1047. * it happens (we leave the reinstall required flag, of course).
  1048. */
  1049. pkg->status= stat_unpacked;
  1050. modstatdb_note(pkg);
  1051. /* Now we delete all the backup files that we made when
  1052. * extracting the archive - except for files listed as conffiles
  1053. * in the new package.
  1054. * This time we count it as an error if something goes wrong.
  1055. *
  1056. * Note that we don't ever delete things that were in the old
  1057. * package as a conffile and don't appear at all in the new.
  1058. * They stay recorded as obsolete conffiles and will eventually
  1059. * (if not taken over by another package) be forgotten.
  1060. */
  1061. for (cfile= newfileslist; cfile; cfile= cfile->next) {
  1062. if (cfile->namenode->flags & fnnf_new_conff) continue;
  1063. fnametmpvb.used= fnameidlu;
  1064. varbufaddstr(&fnametmpvb,namenodetouse(cfile->namenode,pkg)->name);
  1065. varbufaddstr(&fnametmpvb,DPKGTEMPEXT);
  1066. varbufaddc(&fnametmpvb,0);
  1067. ensure_pathname_nonexisting(fnametmpvb.buf);
  1068. }
  1069. /* OK, we're now fully done with the main package.
  1070. * This is quite a nice state, so we don't unwind past here.
  1071. */
  1072. pkg->eflag= eflagv_ok;
  1073. modstatdb_note(pkg);
  1074. push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
  1075. /* Only the removal of the conflictor left to do.
  1076. * The files list for the conflictor is still a little inconsistent in-core,
  1077. * as we have not yet updated the filename->packages mappings; however,
  1078. * the package->filenames mapping is
  1079. */
  1080. for (i = 0 ; i < cflict_index ; i++) {
  1081. /* We need to have the most up-to-date info about which files are what ... */
  1082. ensure_allinstfiles_available();
  1083. removal_bulk(conflictor[i]);
  1084. }
  1085. if (cipaction->arg == act_install) add_to_queue(pkg);
  1086. }