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
= calloc (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
= calloc (1, sizeof (opkg_t
));
192 opkg
->args
= calloc (1, sizeof (args_t
));
193 err
= args_init (opkg
->args
);
201 opkg
->conf
= calloc (1, sizeof (opkg_conf_t
));
202 err
= opkg_conf_init (opkg
->conf
, opkg
->args
);
211 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
216 opkg_free (opkg_t
*opkg
)
218 opkg_assert (opkg
!= NULL
);
220 opkg_conf_deinit (opkg
->conf
);
221 args_deinit (opkg
->args
);
222 free (opkg
->options
);
229 opkg_re_read_config_files (opkg_t
*opkg
)
234 opkg_assert (opkg
!= NULL
);
239 /* Unfortunatly, the easiest way to re-read the config files right now is to
240 * throw away opkg->conf and start again */
242 /* copy the settings we need to keep */
243 a
->autoremove
= c
->autoremove
;
244 a
->force_depends
= c
->force_depends
;
245 a
->force_defaults
= c
->force_defaults
;
246 a
->force_maintainer
= c
->force_maintainer
;
247 a
->force_overwrite
= c
->force_overwrite
;
248 a
->force_downgrade
= c
->force_downgrade
;
249 a
->force_reinstall
= c
->force_reinstall
;
250 a
->force_removal_of_dependent_packages
= c
->force_removal_of_dependent_packages
;
251 a
->force_removal_of_essential_packages
= c
->force_removal_of_essential_packages
;
252 a
->nodeps
= c
->nodeps
;
253 a
->noaction
= c
->noaction
;
254 a
->query_all
= c
->query_all
;
255 a
->verbosity
= c
->verbosity
;
259 if (a
->offline_root
) free (a
->offline_root
);
260 a
->offline_root
= xstrdup(c
->offline_root
);
263 if (c
->offline_root_pre_script_cmd
)
265 if (a
->offline_root_pre_script_cmd
) free (a
->offline_root_pre_script_cmd
);
266 a
->offline_root_pre_script_cmd
= xstrdup(c
->offline_root_pre_script_cmd
);
269 if (c
->offline_root_post_script_cmd
)
271 if (a
->offline_root_post_script_cmd
) free (a
->offline_root_post_script_cmd
);
272 a
->offline_root_post_script_cmd
= xstrdup(c
->offline_root_post_script_cmd
);
278 a
->cache
= xstrdup(c
->cache
);
281 /* throw away old opkg_conf and start again */
282 opkg_conf_deinit (opkg
->conf
);
283 opkg_conf_init (opkg
->conf
, opkg
->args
);
285 free (opkg
->options
);
286 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
292 opkg_get_option (opkg_t
*opkg
, char *option
, void **value
)
295 opkg_option_t
*options
;
297 opkg_assert (opkg
!= NULL
);
298 opkg_assert (option
!= NULL
);
299 opkg_assert (value
!= NULL
);
301 options
= opkg
->options
;
303 /* look up the option
304 * TODO: this would be much better as a hash table
306 while (options
[i
].name
)
308 if (strcmp (options
[i
].name
, option
) != 0)
316 switch (options
[i
].type
)
318 case OPKG_OPT_TYPE_BOOL
:
319 *((int *) value
) = *((int *) options
[i
].value
);
322 case OPKG_OPT_TYPE_INT
:
323 *((int *) value
) = *((int *) options
[i
].value
);
326 case OPKG_OPT_TYPE_STRING
:
327 *((char **)value
) = xstrdup(options
[i
].value
);
334 opkg_set_option (opkg_t
*opkg
, char *option
, void *value
)
336 int i
= 0, found
= 0;
337 opkg_option_t
*options
;
339 opkg_assert (opkg
!= NULL
);
340 opkg_assert (option
!= NULL
);
341 opkg_assert (value
!= NULL
);
343 options
= opkg
->options
;
345 /* look up the option
346 * TODO: this would be much better as a hash table
348 while (options
[i
].name
)
350 if (strcmp (options
[i
].name
, option
) == 0)
360 /* XXX: Warning: Option not found */
365 switch (options
[i
].type
)
367 case OPKG_OPT_TYPE_BOOL
:
368 if (*((int *) value
) == 0)
369 *((int *)options
[i
].value
) = 0;
371 *((int *)options
[i
].value
) = 1;
374 case OPKG_OPT_TYPE_INT
:
375 *((int *) options
[i
].value
) = *((int *) value
);
378 case OPKG_OPT_TYPE_STRING
:
379 *((char **)options
[i
].value
) = xstrdup(value
);
386 * @brief libopkg API: Install package
387 * @param opkg Then opkg handler
388 * @param package_name The name of package in which is going to install
389 * @param progress_callback The callback function that report the status to caller.
392 opkg_install_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
395 char *stripped_filename
;
396 opkg_progress_data_t pdata
;
398 pkg_vec_t
*deps
, *all
;
400 char **unresolved
= NULL
;
402 opkg_assert (opkg
!= NULL
);
403 opkg_assert (package_name
!= NULL
);
406 pkg_info_preinstall_check (opkg
->conf
);
409 /* check to ensure package is not already installed */
410 old
= pkg_hash_fetch_installed_by_name(&opkg
->conf
->pkg_hash
, package_name
);
413 /* XXX: Error: Package is already installed. */
414 return OPKG_PACKAGE_ALREADY_INSTALLED
;
417 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, package_name
, NULL
);
420 /* XXX: Error: Could not find package to install */
421 return OPKG_PACKAGE_NOT_FOUND
;
424 new->state_flag
|= SF_USER
;
426 pdata
.action
= OPKG_INSTALL
;
427 pdata
.package
= pkg_t_to_opkg_package_t (new);
431 /* find dependancies and download them */
432 deps
= pkg_vec_alloc ();
433 /* this function does not return the original package, so we insert it later */
434 ndepends
= pkg_hash_fetch_unsatisfied_dependencies (opkg
->conf
, new, deps
, &unresolved
);
437 /* XXX: Error: Could not satisfy dependencies */
439 return OPKG_DEPENDENCIES_FAILED
;
442 /* insert the package we are installing so that we download it */
443 pkg_vec_insert (deps
, new);
445 /* download package and dependancies */
446 for (i
= 0; i
< deps
->len
; i
++)
449 struct _curl_cb_data cb_data
;
453 if (pkg
->local_filename
)
456 opkg_package_free (pdata
.package
);
457 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
458 pdata
.action
= OPKG_DOWNLOAD
;
460 if (pkg
->src
== NULL
)
462 /* XXX: Error: Package not available from any configured src */
463 return OPKG_PACKAGE_NOT_AVAILABLE
;
466 sprintf_alloc(&url
, "%s/%s", pkg
->src
->value
, pkg
->filename
);
468 /* Get the filename part, without any directory */
469 stripped_filename
= strrchr(pkg
->filename
, '/');
470 if ( ! stripped_filename
)
471 stripped_filename
= pkg
->filename
;
473 sprintf_alloc(&pkg
->local_filename
, "%s/%s", opkg
->conf
->tmp_dir
, stripped_filename
);
475 cb_data
.cb
= progress_callback
;
476 cb_data
.progress_data
= &pdata
;
478 cb_data
.user_data
= user_data
;
479 /* 75% of "install" progress is for downloading */
480 cb_data
.start_range
= 75 * i
/ deps
->len
;
481 cb_data
.finish_range
= 75 * (i
+ 1) / deps
->len
;
483 err
= opkg_download(opkg
->conf
, url
, pkg
->local_filename
,
484 (curl_progress_func
) curl_progress_cb
, &cb_data
);
490 opkg_package_free (pdata
.package
);
491 return OPKG_DOWNLOAD_FAILED
;
497 /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
498 all
= pkg_vec_alloc ();
499 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
500 for (i
= 0; i
< all
->len
; i
++)
502 all
->pkgs
[i
]->parent
->dependencies_checked
= 0;
507 /* 75% of "install" progress is for downloading */
508 opkg_package_free (pdata
.package
);
509 pdata
.package
= pkg_t_to_opkg_package_t (new);
510 pdata
.action
= OPKG_INSTALL
;
511 progress (pdata
, 75);
513 /* unpack the package */
514 err
= opkg_install_pkg(opkg
->conf
, new, 0);
518 opkg_package_free (pdata
.package
);
521 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
522 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
523 case OPKG_INSTALL_ERR_DEPENDENCIES
:
524 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
525 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
526 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
527 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
528 case OPKG_INSTALL_ERR_SHA256
: return OPKG_SHA256_ERROR
;
529 default: return OPKG_UNKNOWN_ERROR
;
533 progress (pdata
, 75);
535 /* run configure scripts, etc. */
536 err
= opkg_configure_packages (opkg
->conf
, NULL
);
539 opkg_package_free (pdata
.package
);
540 return OPKG_UNKNOWN_ERROR
;
543 /* write out status files and file lists */
544 opkg_conf_write_status_files (opkg
->conf
);
545 pkg_write_changed_filelists (opkg
->conf
);
547 progress (pdata
, 100);
548 opkg_package_free (pdata
.package
);
553 opkg_remove_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
557 pkg_t
*pkg_to_remove
;
558 opkg_progress_data_t pdata
;
560 opkg_assert (opkg
!= NULL
);
561 opkg_assert (package_name
!= NULL
);
563 pkg_info_preinstall_check (opkg
->conf
);
565 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, package_name
);
569 /* XXX: Error: Package not installed. */
570 return OPKG_PACKAGE_NOT_INSTALLED
;
573 pdata
.action
= OPKG_REMOVE
;
574 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
578 if (pkg
->state_status
== SS_NOT_INSTALLED
)
580 /* XXX: Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
581 opkg_package_free (pdata
.package
);
582 return OPKG_PACKAGE_NOT_INSTALLED
;
584 progress (pdata
, 25);
586 if (opkg
->conf
->restrict_to_default_dest
)
588 pkg_to_remove
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
590 opkg
->conf
->default_dest
);
594 pkg_to_remove
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, pkg
->name
);
598 progress (pdata
, 75);
600 err
= opkg_remove_pkg (opkg
->conf
, pkg_to_remove
, 0);
602 /* write out status files and file lists */
603 opkg_conf_write_status_files (opkg
->conf
);
604 pkg_write_changed_filelists (opkg
->conf
);
607 progress (pdata
, 100);
608 opkg_package_free (pdata
.package
);
609 return (err
) ? OPKG_UNKNOWN_ERROR
: OPKG_NO_ERROR
;
613 opkg_upgrade_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
617 opkg_progress_data_t pdata
;
621 opkg_assert (opkg
!= NULL
);
622 opkg_assert (package_name
!= NULL
);
624 pkg_info_preinstall_check (opkg
->conf
);
626 if (opkg
->conf
->restrict_to_default_dest
)
628 pkg
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
630 opkg
->conf
->default_dest
);
633 /* XXX: Error: Package not installed in default_dest */
634 return OPKG_PACKAGE_NOT_INSTALLED
;
639 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
,
645 /* XXX: Error: Package not installed */
646 return OPKG_PACKAGE_NOT_INSTALLED
;
649 pdata
.action
= OPKG_INSTALL
;
650 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
653 err
= opkg_upgrade_pkg (opkg
->conf
, pkg
);
654 /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
658 opkg_package_free (pdata
.package
);
661 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
662 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
663 case OPKG_INSTALL_ERR_DEPENDENCIES
:
664 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
665 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
666 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
667 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
668 case OPKG_INSTALL_ERR_SHA256
: return OPKG_SHA256_ERROR
;
669 default: return OPKG_UNKNOWN_ERROR
;
672 progress (pdata
, 75);
674 err
= opkg_configure_packages (opkg
->conf
, NULL
);
676 opkg_package_free (pdata
.package
);
677 return OPKG_UNKNOWN_ERROR
;
680 /* write out status files and file lists */
681 opkg_conf_write_status_files (opkg
->conf
);
682 pkg_write_changed_filelists (opkg
->conf
);
684 progress (pdata
, 100);
685 opkg_package_free (pdata
.package
);
690 opkg_upgrade_all (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
692 pkg_vec_t
*installed
;
696 opkg_progress_data_t pdata
;
698 pdata
.action
= OPKG_INSTALL
;
699 pdata
.package
= NULL
;
701 opkg_assert (opkg
!= NULL
);
704 installed
= pkg_vec_alloc ();
705 pkg_info_preinstall_check (opkg
->conf
);
707 pkg_hash_fetch_all_installed (&opkg
->conf
->pkg_hash
, installed
);
708 for (i
= 0; i
< installed
->len
; i
++)
710 pkg
= installed
->pkgs
[i
];
712 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
713 progress (pdata
, 99 * i
/ installed
->len
);
714 opkg_package_free (pdata
.package
);
716 err
+= opkg_upgrade_pkg (opkg
->conf
, pkg
);
718 pkg_vec_free (installed
);
723 err
= opkg_configure_packages (opkg
->conf
, NULL
);
727 pdata
.package
= NULL
;
728 progress (pdata
, 100);
733 opkg_update_package_lists (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
738 pkg_src_list_elt_t
*iter
;
740 int sources_list_count
, sources_done
;
741 opkg_progress_data_t pdata
;
743 opkg_assert (opkg
!= NULL
);
745 pdata
.action
= OPKG_DOWNLOAD
;
746 pdata
.package
= NULL
;
749 sprintf_alloc (&lists_dir
, "%s",
750 (opkg
->conf
->restrict_to_default_dest
)
751 ? opkg
->conf
->default_dest
->lists_dir
752 : opkg
->conf
->lists_dir
);
754 if (!file_is_dir (lists_dir
))
756 if (file_exists (lists_dir
))
758 /* XXX: Error: file exists but is not a directory */
763 err
= file_mkdir_hier (lists_dir
, 0755);
766 /* XXX: Error: failed to create directory */
772 tmp
= xstrdup("/tmp/opkg.XXXXXX");
774 if (mkdtemp (tmp
) == NULL
)
776 /* XXX: Error: could not create temporary file name */
782 /* count the number of sources so we can give some progress updates */
783 sources_list_count
= 0;
785 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
787 sources_list_count
++;
790 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
792 char *url
, *list_file_name
= NULL
;
794 src
= (pkg_src_t
*)iter
->data
;
796 if (src
->extra_data
) /* debian style? */
797 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
798 src
->gzip
? "Packages.gz" : "Packages");
800 sprintf_alloc (&url
, "%s/%s", src
->value
, src
->gzip
? "Packages.gz" : "Packages");
802 sprintf_alloc (&list_file_name
, "%s/%s", lists_dir
, src
->name
);
806 struct _curl_cb_data cb_data
;
807 char *tmp_file_name
= NULL
;
809 sprintf_alloc (&tmp_file_name
, "%s/%s.gz", tmp
, src
->name
);
811 /* XXX: Note: downloading url */
813 cb_data
.cb
= progress_callback
;
814 cb_data
.progress_data
= &pdata
;
816 cb_data
.user_data
= user_data
;
817 cb_data
.start_range
= 100 * sources_done
/ sources_list_count
;
818 cb_data
.finish_range
= 100 * (sources_done
+ 1) / sources_list_count
;
820 err
= opkg_download (opkg
->conf
, url
, tmp_file_name
, (curl_progress_func
) curl_progress_cb
, &cb_data
);
824 /* XXX: Note: Inflating downloaded file */
825 in
= fopen (tmp_file_name
, "r");
826 out
= fopen (list_file_name
, "w");
835 unlink (tmp_file_name
);
837 free (tmp_file_name
);
840 err
= opkg_download (opkg
->conf
, url
, list_file_name
, NULL
, NULL
);
844 /* XXX: Error: download error */
845 result
= OPKG_DOWNLOAD_FAILED
;
849 #if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
850 if ( opkg
->conf
->check_signature
) {
852 /* download detached signitures to verify the package lists */
853 /* get the url for the sig file */
854 if (src
->extra_data
) /* debian style? */
855 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
858 sprintf_alloc (&url
, "%s/%s", src
->value
, "Packages.sig");
860 /* create filename for signature */
861 sprintf_alloc (&sig_file_name
, "%s/%s.sig", lists_dir
, src
->name
);
863 /* make sure there is no existing signature file */
864 unlink (sig_file_name
);
866 err
= opkg_download (opkg
->conf
, url
, sig_file_name
, NULL
, NULL
);
869 /* XXX: Warning: Download failed */
874 err
= opkg_verify_file (opkg
->conf
, list_file_name
, sig_file_name
);
877 /* XXX: Notice: Signature check passed */
881 /* XXX: Warning: Signature check failed */
884 free (sig_file_name
);
885 free (list_file_name
);
889 /* XXX: Note: Signature check for %s skipped because GPG support was not
890 * enabled in this build
895 progress (pdata
, 100 * sources_done
/ sources_list_count
);
902 /* Now re-read the package lists to update package hash tables. */
903 opkg_re_read_config_files (opkg
);
910 opkg_list_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
916 opkg_assert (callback
);
918 all
= pkg_vec_alloc ();
919 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
920 for (i
= 0; i
< all
->len
; i
++)
923 opkg_package_t
*package
;
927 package
= pkg_t_to_opkg_package_t (pkg
);
928 callback (opkg
, package
, user_data
);
929 opkg_package_free (package
);
938 opkg_list_upgradable_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
940 struct active_list
*head
;
941 struct active_list
*node
;
942 pkg_t
*old
=NULL
, *new = NULL
;
943 static opkg_package_t
* package
=NULL
;
947 opkg_assert (callback
);
949 /* ensure all data is valid */
950 pkg_info_preinstall_check (opkg
->conf
);
952 head
= prepare_upgrade_list(opkg
->conf
);
953 for (node
=active_list_next(head
, head
); node
; active_list_next(head
,node
)) {
954 old
= list_entry(node
, pkg_t
, list
);
955 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, old
->name
, NULL
);
956 package
= pkg_t_to_opkg_package_t (new);
957 callback (opkg
, package
, user_data
);
958 opkg_package_free (package
);
960 active_list_head_delete(head
);
965 opkg_find_package (opkg_t
*opkg
, const char *name
, const char *ver
, const char *arch
, const char *repo
)
968 opkg_package_t
*package
= NULL
;
970 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
974 all
= pkg_vec_alloc ();
975 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
976 for (i
= 0; i
< all
->len
; i
++)
984 if (sstrcmp (pkg
->name
, name
))
988 pkgv
= pkg_version_str_alloc (pkg
);
989 if (sstrcmp (pkgv
, ver
))
996 /* check architecture */
999 if (sstrcmp (pkg
->architecture
, arch
))
1003 /* check repository */
1006 if (sstrcmp (pkg
->src
->name
, repo
))
1011 package
= pkg_t_to_opkg_package_t (pkg
);
1021 #include <curl/curl.h>
1024 * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status.
1025 * @param opkg The opkg_t
1026 * @return return how many repositories cannot access. 0 means all okay.
1028 int opkg_repository_accessibility_check(opkg_t
*opkg
)
1030 pkg_src_list_elt_t
*iter
;
1031 str_list_elt_t
*iter1
;
1038 opkg_assert(opkg
!= NULL
);
1040 src
= str_list_alloc();
1042 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
1044 if (strstr(((pkg_src_t
*)iter
->data
)->value
, "://") &&
1045 index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/'))
1046 stmp
= xstrndup(((pkg_src_t
*)iter
->data
)->value
,
1047 (index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/') - ((pkg_src_t
*)iter
->data
)->value
)*sizeof(char));
1050 stmp
= xstrdup(((pkg_src_t
*)iter
->data
)->value
);
1052 for (iter1
= str_list_first(src
); iter1
; iter1
= str_list_next(src
, iter1
))
1054 if (strstr(iter1
->data
, stmp
))
1060 sprintf_alloc(&repo_ptr
, "%s/index.html",stmp
);
1063 str_list_append(src
, repo_ptr
);
1067 while (repositories
> 0)
1069 iter1
= str_list_pop(src
);
1072 err
= opkg_download(opkg
->conf
, iter1
->data
, "/dev/null", NULL
, NULL
);
1074 if (!(err
== CURLE_OK
||
1075 err
== CURLE_HTTP_RETURNED_ERROR
||
1076 err
== CURLE_FILE_COULDNT_READ_FILE
||
1077 err
== CURLE_REMOTE_FILE_NOT_FOUND
||
1078 err
== CURLE_TFTP_NOTFOUND
1085 str_list_elt_deinit(iter1
);