9 #include "repoinfo_download.h"
19 strcpy(tmpl, "/var/tmp/solvXXXXXX");
31 trydeltadownload(Solvable *s, const char *loc)
34 Pool *pool = repo->pool;
35 struct repoinfo *cinfo = repo->appdata;
38 const unsigned char *chksum;
41 char *matchname = strdup(pool_id2str(pool, s->name));
43 dataiterator_init(&di, pool, repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
44 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
45 while (dataiterator_step(&di))
49 dataiterator_setpos_parent(&di);
50 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
51 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
53 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
54 FOR_PROVIDES(op, pp, s->name)
56 Solvable *os = pool->solvables + op;
57 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
60 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
62 /* base is installed, run sequence check */
70 archstr = pool_id2str(pool, s->arch);
71 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
74 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
75 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
76 if (strchr(seq, '\'') != 0)
78 #if defined(FEDORA) || defined(MAGEIA)
79 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
81 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
83 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
84 continue; /* didn't match */
85 /* looks good, download delta */
87 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
89 continue; /* no way! */
90 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
93 #ifdef ENABLE_SUSEREPO
94 if (cinfo->type == TYPE_SUSETAGS)
96 const char *datadir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DATADIR);
97 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
100 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
102 /* got it, now reconstruct */
103 newfd = opentmpfile();
104 #if defined(FEDORA) || defined(MAGEIA)
105 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
107 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
109 fcntl(fileno(fp), F_SETFD, 0);
116 lseek(newfd, 0, SEEK_SET);
118 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
119 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
125 retfp = fdopen(newfd, "r");
130 dataiterator_free(&di);
131 solv_free(matchname);