1 /* opkg.c - the opkg package management system
3 Thomas Wood <thomas@openedhand.com>
5 Copyright (C) 2008 OpenMoko Inc
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
22 #include "opkg_conf.h"
25 #include "opkg_install.h"
26 #include "opkg_configure.h"
27 #include "opkg_download.h"
28 #include "opkg_remove.h"
29 #include "opkg_upgrade.h"
30 #include "opkg_error.h"
32 #include "sprintf_alloc.h"
33 #include "file_util.h"
35 #include <libbb/libbb.h>
41 opkg_option_t
*options
;
44 #define opkg_assert(expr) if (!(expr)) { \
45 printf ("opkg: file %s: line %d (%s): Assertation '%s' failed",\
46 __FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); }
48 #define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data);
49 #define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0
51 /** Private Functions ***/
56 static opkg_package_t
*
57 pkg_t_to_opkg_package_t (pkg_t
*old
)
61 new = opkg_package_new ();
63 new->name
= xstrdup(old
->name
);
64 new->version
= pkg_version_str_alloc (old
);
65 new->architecture
= xstrdup(old
->architecture
);
67 new->repository
= xstrdup(old
->src
->name
);
68 new->description
= xstrdup(old
->description
);
69 new->tags
= xstrdup(old
->tags
);
70 new->url
= xstrdup(old
->url
);
72 new->size
= (old
->size
) ? atoi (old
->size
) : 0;
73 new->installed
= (old
->state_status
== SS_INSTALLED
);
79 opkg_configure_packages(opkg_conf_t
*conf
, char *pkg_name
)
86 all
= pkg_vec_alloc ();
87 pkg_hash_fetch_available (&conf
->pkg_hash
, all
);
89 for (i
= 0; i
< all
->len
; i
++)
93 if (pkg_name
&& fnmatch (pkg_name
, pkg
->name
, 0))
96 if (pkg
->state_status
== SS_UNPACKED
)
98 r
= opkg_configure (conf
, pkg
);
101 pkg
->state_status
= SS_INSTALLED
;
102 pkg
->parent
->state_status
= SS_INSTALLED
;
103 pkg
->state_flag
&= ~SF_PREFER
;
119 opkg_progress_callback_t cb
;
120 opkg_progress_data_t
*progress_data
;
128 curl_progress_cb (struct _curl_cb_data
*cb_data
,
129 double t
, /* dltotal */
130 double d
, /* dlnow */
134 int p
= (t
) ? d
* 100 / t
: 0;
135 static int prev
= -1;
138 /* prevent the same value being sent twice (can occur due to rounding) */
146 progress
= cb_data
->start_range
+ (d
/ t
* ((cb_data
->finish_range
- cb_data
->start_range
)));
147 cb_data
->progress_data
->percentage
= progress
;
149 (cb_data
->cb
)(cb_data
->opkg
,
150 cb_data
->progress_data
,
165 p
= xcalloc(1, sizeof (opkg_package_t
));
171 opkg_package_free (opkg_package_t
*p
)
175 free (p
->architecture
);
176 free (p
->description
);
179 free (p
->repository
);
190 opkg
= xcalloc(1, sizeof (opkg_t
));
192 opkg
->args
= xcalloc(1, sizeof (args_t
));
193 args_init (opkg
->args
);
195 opkg
->conf
= xcalloc(1, sizeof (opkg_conf_t
));
196 err
= opkg_conf_init (opkg
->conf
, opkg
->args
);
205 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
210 opkg_free (opkg_t
*opkg
)
212 opkg_assert (opkg
!= NULL
);
217 opkg_conf_deinit (opkg
->conf
);
218 args_deinit (opkg
->args
);
219 free (opkg
->options
);
226 opkg_re_read_config_files (opkg_t
*opkg
)
231 opkg_assert (opkg
!= NULL
);
236 /* Unfortunatly, the easiest way to re-read the config files right now is to
237 * throw away opkg->conf and start again */
239 /* copy the settings we need to keep */
240 a
->autoremove
= c
->autoremove
;
241 a
->force_depends
= c
->force_depends
;
242 a
->force_defaults
= c
->force_defaults
;
243 a
->force_maintainer
= c
->force_maintainer
;
244 a
->force_overwrite
= c
->force_overwrite
;
245 a
->force_downgrade
= c
->force_downgrade
;
246 a
->force_reinstall
= c
->force_reinstall
;
247 a
->force_removal_of_dependent_packages
= c
->force_removal_of_dependent_packages
;
248 a
->force_removal_of_essential_packages
= c
->force_removal_of_essential_packages
;
249 a
->nodeps
= c
->nodeps
;
250 a
->noaction
= c
->noaction
;
251 a
->query_all
= c
->query_all
;
252 a
->verbosity
= c
->verbosity
;
256 if (a
->offline_root
) free (a
->offline_root
);
257 a
->offline_root
= xstrdup(c
->offline_root
);
260 if (c
->offline_root_pre_script_cmd
)
262 if (a
->offline_root_pre_script_cmd
) free (a
->offline_root_pre_script_cmd
);
263 a
->offline_root_pre_script_cmd
= xstrdup(c
->offline_root_pre_script_cmd
);
266 if (c
->offline_root_post_script_cmd
)
268 if (a
->offline_root_post_script_cmd
) free (a
->offline_root_post_script_cmd
);
269 a
->offline_root_post_script_cmd
= xstrdup(c
->offline_root_post_script_cmd
);
275 a
->cache
= xstrdup(c
->cache
);
278 /* throw away old opkg_conf and start again */
279 opkg_conf_deinit (opkg
->conf
);
280 opkg_conf_init (opkg
->conf
, opkg
->args
);
282 free (opkg
->options
);
283 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
289 opkg_get_option (opkg_t
*opkg
, char *option
, void **value
)
292 opkg_option_t
*options
;
294 opkg_assert (opkg
!= NULL
);
295 opkg_assert (option
!= NULL
);
296 opkg_assert (value
!= NULL
);
298 options
= opkg
->options
;
300 /* look up the option
301 * TODO: this would be much better as a hash table
303 while (options
[i
].name
)
305 if (strcmp (options
[i
].name
, option
) != 0)
313 switch (options
[i
].type
)
315 case OPKG_OPT_TYPE_BOOL
:
316 *((int *) value
) = *((int *) options
[i
].value
);
319 case OPKG_OPT_TYPE_INT
:
320 *((int *) value
) = *((int *) options
[i
].value
);
323 case OPKG_OPT_TYPE_STRING
:
324 *((char **)value
) = xstrdup(options
[i
].value
);
331 opkg_set_option (opkg_t
*opkg
, char *option
, void *value
)
333 int i
= 0, found
= 0;
334 opkg_option_t
*options
;
336 opkg_assert (opkg
!= NULL
);
337 opkg_assert (option
!= NULL
);
338 opkg_assert (value
!= NULL
);
340 options
= opkg
->options
;
342 /* look up the option
343 * TODO: this would be much better as a hash table
345 while (options
[i
].name
)
347 if (strcmp (options
[i
].name
, option
) == 0)
357 /* XXX: Warning: Option not found */
362 switch (options
[i
].type
)
364 case OPKG_OPT_TYPE_BOOL
:
365 if (*((int *) value
) == 0)
366 *((int *)options
[i
].value
) = 0;
368 *((int *)options
[i
].value
) = 1;
371 case OPKG_OPT_TYPE_INT
:
372 *((int *) options
[i
].value
) = *((int *) value
);
375 case OPKG_OPT_TYPE_STRING
:
376 *((char **)options
[i
].value
) = xstrdup(value
);
383 * @brief libopkg API: Install package
384 * @param opkg Then opkg handler
385 * @param package_name The name of package in which is going to install
386 * @param progress_callback The callback function that report the status to caller.
389 opkg_install_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
392 char *stripped_filename
;
393 opkg_progress_data_t pdata
;
395 pkg_vec_t
*deps
, *all
;
397 char **unresolved
= NULL
;
399 opkg_assert (opkg
!= NULL
);
400 opkg_assert (package_name
!= NULL
);
403 pkg_info_preinstall_check (opkg
->conf
);
406 /* check to ensure package is not already installed */
407 old
= pkg_hash_fetch_installed_by_name(&opkg
->conf
->pkg_hash
, package_name
);
410 /* XXX: Error: Package is already installed. */
411 return OPKG_PACKAGE_ALREADY_INSTALLED
;
414 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, package_name
, NULL
);
417 /* XXX: Error: Could not find package to install */
418 return OPKG_PACKAGE_NOT_FOUND
;
421 new->state_flag
|= SF_USER
;
423 pdata
.action
= OPKG_INSTALL
;
424 pdata
.package
= pkg_t_to_opkg_package_t (new);
428 /* find dependancies and download them */
429 deps
= pkg_vec_alloc ();
430 /* this function does not return the original package, so we insert it later */
431 ndepends
= pkg_hash_fetch_unsatisfied_dependencies (opkg
->conf
, new, deps
, &unresolved
);
434 /* XXX: Error: Could not satisfy dependencies */
436 return OPKG_DEPENDENCIES_FAILED
;
439 /* insert the package we are installing so that we download it */
440 pkg_vec_insert (deps
, new);
442 /* download package and dependancies */
443 for (i
= 0; i
< deps
->len
; i
++)
446 struct _curl_cb_data cb_data
;
450 if (pkg
->local_filename
)
453 opkg_package_free (pdata
.package
);
454 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
455 pdata
.action
= OPKG_DOWNLOAD
;
457 if (pkg
->src
== NULL
)
459 /* XXX: Error: Package not available from any configured src */
460 return OPKG_PACKAGE_NOT_AVAILABLE
;
463 sprintf_alloc(&url
, "%s/%s", pkg
->src
->value
, pkg
->filename
);
465 /* Get the filename part, without any directory */
466 stripped_filename
= strrchr(pkg
->filename
, '/');
467 if ( ! stripped_filename
)
468 stripped_filename
= pkg
->filename
;
470 sprintf_alloc(&pkg
->local_filename
, "%s/%s", opkg
->conf
->tmp_dir
, stripped_filename
);
472 cb_data
.cb
= progress_callback
;
473 cb_data
.progress_data
= &pdata
;
475 cb_data
.user_data
= user_data
;
476 /* 75% of "install" progress is for downloading */
477 cb_data
.start_range
= 75 * i
/ deps
->len
;
478 cb_data
.finish_range
= 75 * (i
+ 1) / deps
->len
;
480 err
= opkg_download(opkg
->conf
, url
, pkg
->local_filename
,
481 (curl_progress_func
) curl_progress_cb
, &cb_data
);
487 opkg_package_free (pdata
.package
);
488 return OPKG_DOWNLOAD_FAILED
;
494 /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
495 all
= pkg_vec_alloc ();
496 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
497 for (i
= 0; i
< all
->len
; i
++)
499 all
->pkgs
[i
]->parent
->dependencies_checked
= 0;
504 /* 75% of "install" progress is for downloading */
505 opkg_package_free (pdata
.package
);
506 pdata
.package
= pkg_t_to_opkg_package_t (new);
507 pdata
.action
= OPKG_INSTALL
;
508 progress (pdata
, 75);
510 /* unpack the package */
511 err
= opkg_install_pkg(opkg
->conf
, new, 0);
515 opkg_package_free (pdata
.package
);
518 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
519 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
520 case OPKG_INSTALL_ERR_DEPENDENCIES
:
521 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
522 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
523 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
524 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
525 case OPKG_INSTALL_ERR_SHA256
: return OPKG_SHA256_ERROR
;
526 default: return OPKG_UNKNOWN_ERROR
;
530 progress (pdata
, 75);
532 /* run configure scripts, etc. */
533 err
= opkg_configure_packages (opkg
->conf
, NULL
);
536 opkg_package_free (pdata
.package
);
537 return OPKG_UNKNOWN_ERROR
;
540 /* write out status files and file lists */
541 opkg_conf_write_status_files (opkg
->conf
);
542 pkg_write_changed_filelists (opkg
->conf
);
544 progress (pdata
, 100);
545 opkg_package_free (pdata
.package
);
550 opkg_remove_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
554 pkg_t
*pkg_to_remove
;
555 opkg_progress_data_t pdata
;
557 opkg_assert (opkg
!= NULL
);
558 opkg_assert (package_name
!= NULL
);
560 pkg_info_preinstall_check (opkg
->conf
);
562 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, package_name
);
566 /* XXX: Error: Package not installed. */
567 return OPKG_PACKAGE_NOT_INSTALLED
;
570 pdata
.action
= OPKG_REMOVE
;
571 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
575 if (pkg
->state_status
== SS_NOT_INSTALLED
)
577 /* XXX: Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
578 opkg_package_free (pdata
.package
);
579 return OPKG_PACKAGE_NOT_INSTALLED
;
581 progress (pdata
, 25);
583 if (opkg
->conf
->restrict_to_default_dest
)
585 pkg_to_remove
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
587 opkg
->conf
->default_dest
);
591 pkg_to_remove
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, pkg
->name
);
595 progress (pdata
, 75);
597 err
= opkg_remove_pkg (opkg
->conf
, pkg_to_remove
, 0);
599 /* write out status files and file lists */
600 opkg_conf_write_status_files (opkg
->conf
);
601 pkg_write_changed_filelists (opkg
->conf
);
604 progress (pdata
, 100);
605 opkg_package_free (pdata
.package
);
606 return (err
) ? OPKG_UNKNOWN_ERROR
: OPKG_NO_ERROR
;
610 opkg_upgrade_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
614 opkg_progress_data_t pdata
;
618 opkg_assert (opkg
!= NULL
);
619 opkg_assert (package_name
!= NULL
);
621 pkg_info_preinstall_check (opkg
->conf
);
623 if (opkg
->conf
->restrict_to_default_dest
)
625 pkg
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
627 opkg
->conf
->default_dest
);
630 /* XXX: Error: Package not installed in default_dest */
631 return OPKG_PACKAGE_NOT_INSTALLED
;
636 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
,
642 /* XXX: Error: Package not installed */
643 return OPKG_PACKAGE_NOT_INSTALLED
;
646 pdata
.action
= OPKG_INSTALL
;
647 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
650 err
= opkg_upgrade_pkg (opkg
->conf
, pkg
);
651 /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
655 opkg_package_free (pdata
.package
);
658 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
659 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
660 case OPKG_INSTALL_ERR_DEPENDENCIES
:
661 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
662 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
663 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
664 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
665 case OPKG_INSTALL_ERR_SHA256
: return OPKG_SHA256_ERROR
;
666 default: return OPKG_UNKNOWN_ERROR
;
669 progress (pdata
, 75);
671 err
= opkg_configure_packages (opkg
->conf
, NULL
);
673 opkg_package_free (pdata
.package
);
674 return OPKG_UNKNOWN_ERROR
;
677 /* write out status files and file lists */
678 opkg_conf_write_status_files (opkg
->conf
);
679 pkg_write_changed_filelists (opkg
->conf
);
681 progress (pdata
, 100);
682 opkg_package_free (pdata
.package
);
687 opkg_upgrade_all (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
689 pkg_vec_t
*installed
;
693 opkg_progress_data_t pdata
;
695 pdata
.action
= OPKG_INSTALL
;
696 pdata
.package
= NULL
;
698 opkg_assert (opkg
!= NULL
);
701 installed
= pkg_vec_alloc ();
702 pkg_info_preinstall_check (opkg
->conf
);
704 pkg_hash_fetch_all_installed (&opkg
->conf
->pkg_hash
, installed
);
705 for (i
= 0; i
< installed
->len
; i
++)
707 pkg
= installed
->pkgs
[i
];
709 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
710 progress (pdata
, 99 * i
/ installed
->len
);
711 opkg_package_free (pdata
.package
);
713 err
+= opkg_upgrade_pkg (opkg
->conf
, pkg
);
715 pkg_vec_free (installed
);
720 err
= opkg_configure_packages (opkg
->conf
, NULL
);
724 pdata
.package
= NULL
;
725 progress (pdata
, 100);
730 opkg_update_package_lists (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
735 pkg_src_list_elt_t
*iter
;
737 int sources_list_count
, sources_done
;
738 opkg_progress_data_t pdata
;
740 opkg_assert (opkg
!= NULL
);
742 pdata
.action
= OPKG_DOWNLOAD
;
743 pdata
.package
= NULL
;
746 sprintf_alloc (&lists_dir
, "%s",
747 (opkg
->conf
->restrict_to_default_dest
)
748 ? opkg
->conf
->default_dest
->lists_dir
749 : opkg
->conf
->lists_dir
);
751 if (!file_is_dir (lists_dir
))
753 if (file_exists (lists_dir
))
755 /* XXX: Error: file exists but is not a directory */
760 err
= file_mkdir_hier (lists_dir
, 0755);
763 /* XXX: Error: failed to create directory */
769 tmp
= xstrdup("/tmp/opkg.XXXXXX");
771 if (mkdtemp (tmp
) == NULL
)
773 /* XXX: Error: could not create temporary file name */
779 /* count the number of sources so we can give some progress updates */
780 sources_list_count
= 0;
782 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
784 sources_list_count
++;
787 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
789 char *url
, *list_file_name
= NULL
;
791 src
= (pkg_src_t
*)iter
->data
;
793 if (src
->extra_data
) /* debian style? */
794 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
795 src
->gzip
? "Packages.gz" : "Packages");
797 sprintf_alloc (&url
, "%s/%s", src
->value
, src
->gzip
? "Packages.gz" : "Packages");
799 sprintf_alloc (&list_file_name
, "%s/%s", lists_dir
, src
->name
);
803 struct _curl_cb_data cb_data
;
804 char *tmp_file_name
= NULL
;
806 sprintf_alloc (&tmp_file_name
, "%s/%s.gz", tmp
, src
->name
);
808 /* XXX: Note: downloading url */
810 cb_data
.cb
= progress_callback
;
811 cb_data
.progress_data
= &pdata
;
813 cb_data
.user_data
= user_data
;
814 cb_data
.start_range
= 100 * sources_done
/ sources_list_count
;
815 cb_data
.finish_range
= 100 * (sources_done
+ 1) / sources_list_count
;
817 err
= opkg_download (opkg
->conf
, url
, tmp_file_name
, (curl_progress_func
) curl_progress_cb
, &cb_data
);
821 /* XXX: Note: Inflating downloaded file */
822 in
= fopen (tmp_file_name
, "r");
823 out
= fopen (list_file_name
, "w");
832 unlink (tmp_file_name
);
834 free (tmp_file_name
);
837 err
= opkg_download (opkg
->conf
, url
, list_file_name
, NULL
, NULL
);
841 /* XXX: Error: download error */
842 result
= OPKG_DOWNLOAD_FAILED
;
846 #if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
847 if ( opkg
->conf
->check_signature
) {
849 /* download detached signitures to verify the package lists */
850 /* get the url for the sig file */
851 if (src
->extra_data
) /* debian style? */
852 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
855 sprintf_alloc (&url
, "%s/%s", src
->value
, "Packages.sig");
857 /* create filename for signature */
858 sprintf_alloc (&sig_file_name
, "%s/%s.sig", lists_dir
, src
->name
);
860 /* make sure there is no existing signature file */
861 unlink (sig_file_name
);
863 err
= opkg_download (opkg
->conf
, url
, sig_file_name
, NULL
, NULL
);
866 /* XXX: Warning: Download failed */
871 err
= opkg_verify_file (opkg
->conf
, list_file_name
, sig_file_name
);
874 /* XXX: Notice: Signature check passed */
878 /* XXX: Warning: Signature check failed */
881 free (sig_file_name
);
882 free (list_file_name
);
886 /* XXX: Note: Signature check for %s skipped because GPG support was not
887 * enabled in this build
892 progress (pdata
, 100 * sources_done
/ sources_list_count
);
899 /* Now re-read the package lists to update package hash tables. */
900 opkg_re_read_config_files (opkg
);
907 opkg_list_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
913 opkg_assert (callback
);
915 all
= pkg_vec_alloc ();
916 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
917 for (i
= 0; i
< all
->len
; i
++)
920 opkg_package_t
*package
;
924 package
= pkg_t_to_opkg_package_t (pkg
);
925 callback (opkg
, package
, user_data
);
926 opkg_package_free (package
);
935 opkg_list_upgradable_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
937 struct active_list
*head
;
938 struct active_list
*node
;
939 pkg_t
*old
=NULL
, *new = NULL
;
940 static opkg_package_t
* package
=NULL
;
944 opkg_assert (callback
);
946 /* ensure all data is valid */
947 pkg_info_preinstall_check (opkg
->conf
);
949 head
= prepare_upgrade_list(opkg
->conf
);
950 for (node
=active_list_next(head
, head
); node
; active_list_next(head
,node
)) {
951 old
= list_entry(node
, pkg_t
, list
);
952 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, old
->name
, NULL
);
953 package
= pkg_t_to_opkg_package_t (new);
954 callback (opkg
, package
, user_data
);
955 opkg_package_free (package
);
957 active_list_head_delete(head
);
962 opkg_find_package (opkg_t
*opkg
, const char *name
, const char *ver
, const char *arch
, const char *repo
)
965 opkg_package_t
*package
= NULL
;
967 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
971 all
= pkg_vec_alloc ();
972 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
973 for (i
= 0; i
< all
->len
; i
++)
981 if (sstrcmp (pkg
->name
, name
))
985 pkgv
= pkg_version_str_alloc (pkg
);
986 if (sstrcmp (pkgv
, ver
))
993 /* check architecture */
996 if (sstrcmp (pkg
->architecture
, arch
))
1000 /* check repository */
1003 if (sstrcmp (pkg
->src
->name
, repo
))
1008 package
= pkg_t_to_opkg_package_t (pkg
);
1018 #include <curl/curl.h>
1021 * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status.
1022 * @param opkg The opkg_t
1023 * @return return how many repositories cannot access. 0 means all okay.
1025 int opkg_repository_accessibility_check(opkg_t
*opkg
)
1027 pkg_src_list_elt_t
*iter
;
1028 str_list_elt_t
*iter1
;
1035 opkg_assert(opkg
!= NULL
);
1037 src
= str_list_alloc();
1039 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
1041 if (strstr(((pkg_src_t
*)iter
->data
)->value
, "://") &&
1042 index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/'))
1043 stmp
= xstrndup(((pkg_src_t
*)iter
->data
)->value
,
1044 (index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/') - ((pkg_src_t
*)iter
->data
)->value
)*sizeof(char));
1047 stmp
= xstrdup(((pkg_src_t
*)iter
->data
)->value
);
1049 for (iter1
= str_list_first(src
); iter1
; iter1
= str_list_next(src
, iter1
))
1051 if (strstr(iter1
->data
, stmp
))
1057 sprintf_alloc(&repo_ptr
, "%s/index.html",stmp
);
1060 str_list_append(src
, repo_ptr
);
1064 while (repositories
> 0)
1066 iter1
= str_list_pop(src
);
1069 err
= opkg_download(opkg
->conf
, iter1
->data
, "/dev/null", NULL
, NULL
);
1071 if (!(err
== CURLE_OK
||
1072 err
== CURLE_HTTP_RETURNED_ERROR
||
1073 err
== CURLE_FILE_COULDNT_READ_FILE
||
1074 err
== CURLE_REMOTE_FILE_NOT_FOUND
||
1075 err
== CURLE_TFTP_NOTFOUND
1082 str_list_elt_deinit(iter1
);