processarc.c 48 KB

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