processarc.c 47 KB

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