00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021
00022 #include <stdlib.h>
00023 #include <string.h>
00024
00025
00026 #include "delta.h"
00027 #include "error.h"
00028 #include "util.h"
00029 #include "log.h"
00030 #include "alpm_list.h"
00031 #include "alpm.h"
00032
00033
00034
00035
00036
00037
00038 const char SYMEXPORT *alpm_delta_get_from(pmdelta_t *delta)
00039 {
00040 ALPM_LOG_FUNC;
00041
00042
00043 ASSERT(delta != NULL, return(NULL));
00044
00045 return(delta->from);
00046 }
00047
00048 const char SYMEXPORT *alpm_delta_get_to(pmdelta_t *delta)
00049 {
00050 ALPM_LOG_FUNC;
00051
00052
00053 ASSERT(delta != NULL, return(NULL));
00054
00055 return(delta->to);
00056 }
00057
00058 unsigned long SYMEXPORT alpm_delta_get_size(pmdelta_t *delta)
00059 {
00060 ALPM_LOG_FUNC;
00061
00062
00063 ASSERT(delta != NULL, return(-1));
00064
00065 return(delta->size);
00066 }
00067
00068 const char SYMEXPORT *alpm_delta_get_filename(pmdelta_t *delta)
00069 {
00070 ALPM_LOG_FUNC;
00071
00072
00073 ASSERT(delta != NULL, return(NULL));
00074
00075 return(delta->filename);
00076 }
00077
00078 const char SYMEXPORT *alpm_delta_get_md5sum(pmdelta_t *delta)
00079 {
00080 ALPM_LOG_FUNC;
00081
00082
00083 ASSERT(delta != NULL, return(NULL));
00084
00085 return(delta->md5sum);
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 unsigned long _alpm_delta_path_size(alpm_list_t *deltas)
00097 {
00098 unsigned long sum = 0;
00099 alpm_list_t *dlts = deltas;
00100
00101 while(dlts) {
00102 pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
00103 sum += d->size;
00104
00105 dlts = alpm_list_next(dlts);
00106 }
00107
00108 return(sum);
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118 unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas)
00119 {
00120 unsigned long sum = 0;
00121 alpm_list_t *dlts = deltas;
00122
00123 while(dlts) {
00124 pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
00125 char *fname = _alpm_filecache_find(d->filename);
00126
00127 if(!fname) {
00128 sum += d->size;
00129 }
00130
00131 FREE(fname);
00132
00133 dlts = alpm_list_next(dlts);
00134 }
00135
00136 return(sum);
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 static alpm_list_t *shortest_delta_path(alpm_list_t *deltas,
00156 const char *from, const char *to, alpm_list_t *path)
00157 {
00158 alpm_list_t *d;
00159 alpm_list_t *shortest = NULL;
00160
00161
00162 if(strcmp(from, to) == 0) {
00163 return(path);
00164 }
00165
00166 for(d = deltas; d; d = alpm_list_next(d)) {
00167 pmdelta_t *v = alpm_list_getdata(d);
00168
00169
00170
00171 if(alpm_list_find_ptr(path, v)) {
00172 continue;
00173 }
00174
00175
00176
00177
00178 if(strcmp(v->from, from) == 0) {
00179 alpm_list_t *newpath = alpm_list_copy(path);
00180 newpath = alpm_list_add(newpath, v);
00181 newpath = shortest_delta_path(deltas, v->to, to, newpath);
00182
00183 if(newpath != NULL) {
00184
00185
00186 if(shortest == NULL) {
00187 shortest = newpath;
00188 } else if(_alpm_delta_path_size(shortest) > _alpm_delta_path_size(newpath)) {
00189 alpm_list_free(shortest);
00190 shortest = newpath;
00191 } else {
00192 alpm_list_free(newpath);
00193 }
00194 }
00195 }
00196 }
00197
00198 alpm_list_free(path);
00199
00200 return(shortest);
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 alpm_list_t *_alpm_shortest_delta_path(alpm_list_t *deltas, const char *from,
00217 const char *to)
00218 {
00219 alpm_list_t *path = NULL;
00220
00221 path = shortest_delta_path(deltas, from, to, path);
00222
00223 return(path);
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 pmdelta_t *_alpm_delta_parse(char *line)
00235 {
00236 pmdelta_t *delta;
00237 char *tmp = line, *tmp2;
00238
00239 CALLOC(delta, 1, sizeof(pmdelta_t), RET_ERR(PM_ERR_MEMORY, NULL));
00240
00241 tmp2 = tmp;
00242 tmp = strchr(tmp, ' ');
00243 *(tmp++) = '\0';
00244 strncpy(delta->from, tmp2, DLT_VERSION_LEN);
00245
00246 tmp2 = tmp;
00247 tmp = strchr(tmp, ' ');
00248 *(tmp++) = '\0';
00249 strncpy(delta->to, tmp2, DLT_VERSION_LEN);
00250
00251 tmp2 = tmp;
00252 tmp = strchr(tmp, ' ');
00253 *(tmp++) = '\0';
00254 delta->size = atol(tmp2);
00255
00256 tmp2 = tmp;
00257 tmp = strchr(tmp, ' ');
00258 *(tmp++) = '\0';
00259 strncpy(delta->filename, tmp2, DLT_FILENAME_LEN);
00260
00261 strncpy(delta->md5sum, tmp, DLT_MD5SUM_LEN);
00262
00263 return(delta);
00264 }
00265
00266