Rev 5727 | Rev 5729 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5727 | Rev 5728 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #include |
|
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include |
6 | #include |
7 | #include |
- | 8 | #include |
|
- | 9 | ||
7 | #include "collection.h" |
10 | #include "package.h" |
8 | #include "http.h" |
11 | #include "http.h" |
Line 9... | Line 12... | ||
9 | 12 | ||
Line 140... | Line 143... | ||
140 | collection = load_collection_file(tmp_path); |
143 | collection = load_collection_file(tmp_path); |
Line 141... | Line 144... | ||
141 | 144 | ||
142 | if(collection && build_install_list(&install_list, collection)) |
145 | if(collection && build_install_list(&install_list, collection)) |
143 | { |
146 | { |
- | 147 | if(build_download_list(&download_list, &install_list)) |
|
- | 148 | do_download(&download_list); |
|
- | 149 | ||
- | 150 | if(!list_empty(&download_list)) |
|
- | 151 | remove_packages(&install_list, &download_list); |
|
- | 152 | ||
- | 153 | list_for_each_entry(pkg, &install_list, list) |
|
- | 154 | printf("install package %s-%s\n", pkg->name, pkg->version); |
|
- | 155 | }; |
|
- | 156 | } |
|
- | 157 | ||
- | 158 | return 0; |
|
- | 159 | ||
- | 160 | err_init: |
|
- | 161 | printf("HTTP library initialization failed\n"); |
|
- | 162 | return -1; |
|
- | 163 | } |
|
- | 164 | ||
144 | if(build_download_list(&download_list, &install_list)) |
165 | int build_install_list(list_t *list, collection_t *collection) |
- | 166 | { |
|
- | 167 | pkg_group_t *gr; |
|
- | 168 | int count = 0; |
|
- | 169 | ||
- | 170 | list_for_each_entry(gr, &collection->groups, list) |
|
- | 171 | { |
|
- | 172 | package_t *pkg, *tmp; |
|
- | 173 | ||
- | 174 | list_for_each_entry(tmp, &gr->packages, list) |
|
- | 175 | { |
|
- | 176 | pkg = (package_t*)malloc(sizeof(package_t)); |
|
- | 177 | ||
- | 178 | INIT_LIST_HEAD(&pkg->file_list); |
|
- | 179 | pkg->id = tmp->id; |
|
- | 180 | pkg->name = strdup(tmp->name); |
|
- | 181 | pkg->version = strdup(tmp->version); |
|
- | 182 | pkg->filename = strdup(tmp->filename); |
|
- | 183 | pkg->description = strdup(tmp->description); |
|
- | 184 | list_add_tail(&pkg->list, list); |
|
- | 185 | count++; |
|
- | 186 | } |
|
- | 187 | }; |
|
- | 188 | return count; |
|
- | 189 | } |
|
- | 190 | ||
- | 191 | int build_download_list(list_t *download, list_t *src) |
|
- | 192 | { |
|
- | 193 | int count = 0; |
|
- | 194 | char *cache_path; |
|
- | 195 | package_t *pkg, *tmp; |
|
- | 196 | fileinfo_t info; |
|
- | 197 | list_for_each_entry(tmp, src, list) |
|
- | 198 | { |
|
- | 199 | cache_path = make_cache_path(tmp->filename); |
|
- | 200 | ||
- | 201 | if( get_fileinfo(cache_path, &info) != 0) |
|
- | 202 | { |
|
- | 203 | pkg = (package_t*)malloc(sizeof(package_t)); |
|
- | 204 | ||
- | 205 | INIT_LIST_HEAD(&pkg->file_list); |
|
- | 206 | pkg->id = tmp->id; |
|
- | 207 | pkg->name = strdup(tmp->name); |
|
- | 208 | pkg->version = strdup(tmp->version); |
|
- | 209 | pkg->filename = strdup(tmp->filename); |
|
- | 210 | pkg->description = strdup(tmp->description); |
|
- | 211 | list_add_tail(&pkg->list, download); |
|
- | 212 | count++; |
|
- | 213 | }; |
|
- | 214 | } |
|
- | 215 | return count; |
|
- | 216 | }; |
|
- | 217 | ||
- | 218 | void do_download(list_t *download_list) |
|
- | 219 | { |
|
- | 220 | package_t *pkg, *tmp; |
|
- | 221 | char *cache_path; |
|
- | 222 | int count; |
|
145 | { |
223 | |
146 | list_for_each_entry(pkg, &download_list, list) |
224 | list_for_each_entry_safe(pkg, tmp, download_list, list) |
147 | { |
225 | { |
148 | printf("package %s-%s\n", pkg->name, pkg->version); |
226 | printf("package %s-%s\n", pkg->name, pkg->version); |
149 | cache_path = make_cache_path(pkg->filename); |
227 | cache_path = make_cache_path(pkg->filename); |
150 | count = http_load_file(cache_path, make_url(pkg->filename)); |
228 | count = http_load_file(cache_path, make_url(pkg->filename)); |
- | 229 | printf("%s loaded %d bytes\n",cache_path, count); |
|
151 | printf("%s loaded %d bytes\n",cache_path, count); |
230 | if( !test_archive(cache_path)) |
152 | }; |
231 | list_del_pkg(pkg); |
153 | }; |
232 | else /*delete file*/; |
154 | }; |
233 | }; |
Line -... | Line 234... | ||
- | 234 | } |
|
- | 235 | ||
155 | } |
236 | void remove_packages(list_t *install, list_t *missed) |
Line -... | Line 237... | ||
- | 237 | { |
|
- | 238 | package_t *mpkg, *mtmp, *ipkg, *itmp; |
|
- | 239 | ||
156 | 240 | list_for_each_entry_safe(mpkg, mtmp, missed, list) |
|
- | 241 | { |
|
- | 242 | list_for_each_entry_safe(ipkg, itmp, install, list) |
|
157 | return 0; |
243 | { |
- | 244 | if(ipkg->id == mpkg->id) |
|
158 | 245 | { |
|
159 | err_init: |
246 | printf("skip missed package %s-%s\n", ipkg->name, ipkg->version); |
- | 247 | list_del_pkg(ipkg); |
|
- | 248 | }; |
|
- | 249 | } |