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>
37 struct errlist
* error_list
;
43 opkg_option_t
*options
;
46 #define opkg_assert(expr) if (!(expr)) { \
47 printf ("opkg: file %s: line %d (%s): Assertation '%s' failed",\
48 __FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); }
50 #define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data);
51 #define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0
53 /** Private Functions ***/
58 static opkg_package_t
*
59 pkg_t_to_opkg_package_t (pkg_t
*old
)
63 new = opkg_package_new ();
65 #define sstrdup(x) (x) ? strdup (x) : NULL;
67 new->name
= sstrdup (old
->name
);
68 new->version
= pkg_version_str_alloc (old
);
69 new->architecture
= sstrdup (old
->architecture
);
71 new->repository
= sstrdup (old
->src
->name
);
72 new->description
= sstrdup (old
->description
);
73 new->tags
= sstrdup (old
->tags
);
74 new->url
= sstrdup (old
->url
);
78 new->size
= (old
->size
) ? atoi (old
->size
) : 0;
79 new->installed
= (old
->state_status
== SS_INSTALLED
);
85 opkg_configure_packages(opkg_conf_t
*conf
, char *pkg_name
)
92 all
= pkg_vec_alloc ();
93 pkg_hash_fetch_available (&conf
->pkg_hash
, all
);
95 for (i
= 0; i
< all
->len
; i
++)
99 if (pkg_name
&& fnmatch (pkg_name
, pkg
->name
, 0))
102 if (pkg
->state_status
== SS_UNPACKED
)
104 r
= opkg_configure (conf
, pkg
);
107 pkg
->state_status
= SS_INSTALLED
;
108 pkg
->parent
->state_status
= SS_INSTALLED
;
109 pkg
->state_flag
&= ~SF_PREFER
;
125 opkg_progress_callback_t cb
;
126 opkg_progress_data_t
*progress_data
;
134 curl_progress_cb (struct _curl_cb_data
*cb_data
,
135 double t
, /* dltotal */
136 double d
, /* dlnow */
140 int p
= (t
) ? d
* 100 / t
: 0;
141 static int prev
= -1;
144 /* prevent the same value being sent twice (can occur due to rounding) */
152 progress
= cb_data
->start_range
+ (d
/ t
* ((cb_data
->finish_range
- cb_data
->start_range
)));
153 cb_data
->progress_data
->percentage
= progress
;
155 (cb_data
->cb
)(cb_data
->opkg
,
156 cb_data
->progress_data
,
171 p
= calloc (1, sizeof (opkg_package_t
));
177 opkg_package_free (opkg_package_t
*p
)
181 free (p
->architecture
);
182 free (p
->description
);
185 free (p
->repository
);
196 opkg
= calloc (1, sizeof (opkg_t
));
198 opkg
->args
= calloc (1, sizeof (args_t
));
199 err
= args_init (opkg
->args
);
207 opkg
->conf
= calloc (1, sizeof (opkg_conf_t
));
208 err
= opkg_conf_init (opkg
->conf
, opkg
->args
);
217 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
222 opkg_free (opkg_t
*opkg
)
224 opkg_assert (opkg
!= NULL
);
226 opkg_conf_deinit (opkg
->conf
);
227 args_deinit (opkg
->args
);
228 free (opkg
->options
);
235 opkg_re_read_config_files (opkg_t
*opkg
)
240 opkg_assert (opkg
!= NULL
);
245 /* Unfortunatly, the easiest way to re-read the config files right now is to
246 * throw away opkg->conf and start again */
248 /* copy the settings we need to keep */
249 a
->autoremove
= c
->autoremove
;
250 a
->force_depends
= c
->force_depends
;
251 a
->force_defaults
= c
->force_defaults
;
252 a
->force_maintainer
= c
->force_maintainer
;
253 a
->force_overwrite
= c
->force_overwrite
;
254 a
->force_downgrade
= c
->force_downgrade
;
255 a
->force_reinstall
= c
->force_reinstall
;
256 a
->force_removal_of_dependent_packages
= c
->force_removal_of_dependent_packages
;
257 a
->force_removal_of_essential_packages
= c
->force_removal_of_essential_packages
;
258 a
->nodeps
= c
->nodeps
;
259 a
->noaction
= c
->noaction
;
260 a
->query_all
= c
->query_all
;
261 a
->verbosity
= c
->verbosity
;
265 if (a
->offline_root
) free (a
->offline_root
);
266 a
->offline_root
= strdup (c
->offline_root
);
269 if (c
->offline_root_pre_script_cmd
)
271 if (a
->offline_root_pre_script_cmd
) free (a
->offline_root_pre_script_cmd
);
272 a
->offline_root_pre_script_cmd
= strdup (c
->offline_root_pre_script_cmd
);
275 if (c
->offline_root_post_script_cmd
)
277 if (a
->offline_root_post_script_cmd
) free (a
->offline_root_post_script_cmd
);
278 a
->offline_root_post_script_cmd
= strdup (c
->offline_root_post_script_cmd
);
284 a
->cache
= strdup(c
->cache
);
287 /* throw away old opkg_conf and start again */
288 opkg_conf_deinit (opkg
->conf
);
289 opkg_conf_init (opkg
->conf
, opkg
->args
);
291 free (opkg
->options
);
292 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
298 opkg_get_option (opkg_t
*opkg
, char *option
, void **value
)
301 opkg_option_t
*options
;
303 opkg_assert (opkg
!= NULL
);
304 opkg_assert (option
!= NULL
);
305 opkg_assert (value
!= NULL
);
307 options
= opkg
->options
;
309 /* look up the option
310 * TODO: this would be much better as a hash table
312 while (options
[i
].name
)
314 if (strcmp (options
[i
].name
, option
) != 0)
322 switch (options
[i
].type
)
324 case OPKG_OPT_TYPE_BOOL
:
325 *((int *) value
) = *((int *) options
[i
].value
);
328 case OPKG_OPT_TYPE_INT
:
329 *((int *) value
) = *((int *) options
[i
].value
);
332 case OPKG_OPT_TYPE_STRING
:
333 *((char **)value
) = strdup (options
[i
].value
);
340 opkg_set_option (opkg_t
*opkg
, char *option
, void *value
)
342 int i
= 0, found
= 0;
343 opkg_option_t
*options
;
345 opkg_assert (opkg
!= NULL
);
346 opkg_assert (option
!= NULL
);
347 opkg_assert (value
!= NULL
);
349 options
= opkg
->options
;
351 /* look up the option
352 * TODO: this would be much better as a hash table
354 while (options
[i
].name
)
356 if (strcmp (options
[i
].name
, option
) == 0)
366 /* XXX: Warning: Option not found */
371 switch (options
[i
].type
)
373 case OPKG_OPT_TYPE_BOOL
:
374 if (*((int *) value
) == 0)
375 *((int *)options
[i
].value
) = 0;
377 *((int *)options
[i
].value
) = 1;
380 case OPKG_OPT_TYPE_INT
:
381 *((int *) options
[i
].value
) = *((int *) value
);
384 case OPKG_OPT_TYPE_STRING
:
385 *((char **)options
[i
].value
) = strdup (value
);
392 * @brief libopkg API: Install package
393 * @param opkg Then opkg handler
394 * @param package_name The name of package in which is going to install
395 * @param progress_callback The callback function that report the status to caller.
398 opkg_install_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
401 char *stripped_filename
;
402 opkg_progress_data_t pdata
;
404 pkg_vec_t
*deps
, *all
;
406 char **unresolved
= NULL
;
408 opkg_assert (opkg
!= NULL
);
409 opkg_assert (package_name
!= NULL
);
412 pkg_info_preinstall_check (opkg
->conf
);
415 /* check to ensure package is not already installed */
416 old
= pkg_hash_fetch_installed_by_name(&opkg
->conf
->pkg_hash
, package_name
);
419 /* XXX: Error: Package is already installed. */
420 return OPKG_PACKAGE_ALREADY_INSTALLED
;
423 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, package_name
, NULL
);
426 /* XXX: Error: Could not find package to install */
427 return OPKG_PACKAGE_NOT_FOUND
;
430 new->state_flag
|= SF_USER
;
432 pdata
.action
= OPKG_INSTALL
;
433 pdata
.package
= pkg_t_to_opkg_package_t (new);
437 /* find dependancies and download them */
438 deps
= pkg_vec_alloc ();
439 /* this function does not return the original package, so we insert it later */
440 ndepends
= pkg_hash_fetch_unsatisfied_dependencies (opkg
->conf
, new, deps
, &unresolved
);
443 /* XXX: Error: Could not satisfy dependencies */
445 return OPKG_DEPENDENCIES_FAILED
;
448 /* insert the package we are installing so that we download it */
449 pkg_vec_insert (deps
, new);
451 /* download package and dependancies */
452 for (i
= 0; i
< deps
->len
; i
++)
455 struct _curl_cb_data cb_data
;
459 if (pkg
->local_filename
)
462 opkg_package_free (pdata
.package
);
463 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
464 pdata
.action
= OPKG_DOWNLOAD
;
466 if (pkg
->src
== NULL
)
468 /* XXX: Error: Package not available from any configured src */
469 return OPKG_PACKAGE_NOT_AVAILABLE
;
472 sprintf_alloc(&url
, "%s/%s", pkg
->src
->value
, pkg
->filename
);
474 /* Get the filename part, without any directory */
475 stripped_filename
= strrchr(pkg
->filename
, '/');
476 if ( ! stripped_filename
)
477 stripped_filename
= pkg
->filename
;
479 sprintf_alloc(&pkg
->local_filename
, "%s/%s", opkg
->conf
->tmp_dir
, stripped_filename
);
481 cb_data
.cb
= progress_callback
;
482 cb_data
.progress_data
= &pdata
;
484 cb_data
.user_data
= user_data
;
485 /* 75% of "install" progress is for downloading */
486 cb_data
.start_range
= 75 * i
/ deps
->len
;
487 cb_data
.finish_range
= 75 * (i
+ 1) / deps
->len
;
489 err
= opkg_download(opkg
->conf
, url
, pkg
->local_filename
,
490 (curl_progress_func
) curl_progress_cb
, &cb_data
);
496 opkg_package_free (pdata
.package
);
497 return OPKG_DOWNLOAD_FAILED
;
503 /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
504 all
= pkg_vec_alloc ();
505 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
506 for (i
= 0; i
< all
->len
; i
++)
508 all
->pkgs
[i
]->parent
->dependencies_checked
= 0;
513 /* 75% of "install" progress is for downloading */
514 opkg_package_free (pdata
.package
);
515 pdata
.package
= pkg_t_to_opkg_package_t (new);
516 pdata
.action
= OPKG_INSTALL
;
517 progress (pdata
, 75);
519 /* unpack the package */
520 err
= opkg_install_pkg(opkg
->conf
, new, 0);
524 opkg_package_free (pdata
.package
);
527 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
528 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
529 case OPKG_INSTALL_ERR_DEPENDENCIES
:
530 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
531 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
532 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
533 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
534 case OPKG_INSTALL_ERR_SHA256
: return OPKG_SHA256_ERROR
;
535 default: return OPKG_UNKNOWN_ERROR
;
539 progress (pdata
, 75);
541 /* run configure scripts, etc. */
542 err
= opkg_configure_packages (opkg
->conf
, NULL
);
545 opkg_package_free (pdata
.package
);
546 return OPKG_UNKNOWN_ERROR
;
549 /* write out status files and file lists */
550 opkg_conf_write_status_files (opkg
->conf
);
551 pkg_write_changed_filelists (opkg
->conf
);
553 progress (pdata
, 100);
554 opkg_package_free (pdata
.package
);
559 opkg_remove_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
563 pkg_t
*pkg_to_remove
;
564 opkg_progress_data_t pdata
;
566 opkg_assert (opkg
!= NULL
);
567 opkg_assert (package_name
!= NULL
);
569 pkg_info_preinstall_check (opkg
->conf
);
571 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, package_name
);
575 /* XXX: Error: Package not installed. */
576 return OPKG_PACKAGE_NOT_INSTALLED
;
579 pdata
.action
= OPKG_REMOVE
;
580 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
584 if (pkg
->state_status
== SS_NOT_INSTALLED
)
586 /* XXX: Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
587 opkg_package_free (pdata
.package
);
588 return OPKG_PACKAGE_NOT_INSTALLED
;
590 progress (pdata
, 25);
592 if (opkg
->conf
->restrict_to_default_dest
)
594 pkg_to_remove
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
596 opkg
->conf
->default_dest
);
600 pkg_to_remove
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, pkg
->name
);
604 progress (pdata
, 75);
606 err
= opkg_remove_pkg (opkg
->conf
, pkg_to_remove
, 0);
608 /* write out status files and file lists */
609 opkg_conf_write_status_files (opkg
->conf
);
610 pkg_write_changed_filelists (opkg
->conf
);
613 progress (pdata
, 100);
614 opkg_package_free (pdata
.package
);
615 return (err
) ? OPKG_UNKNOWN_ERROR
: OPKG_NO_ERROR
;
619 opkg_upgrade_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
623 opkg_progress_data_t pdata
;
627 opkg_assert (opkg
!= NULL
);
628 opkg_assert (package_name
!= NULL
);
630 pkg_info_preinstall_check (opkg
->conf
);
632 if (opkg
->conf
->restrict_to_default_dest
)
634 pkg
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
636 opkg
->conf
->default_dest
);
639 /* XXX: Error: Package not installed in default_dest */
640 return OPKG_PACKAGE_NOT_INSTALLED
;
645 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
,
651 /* XXX: Error: Package not installed */
652 return OPKG_PACKAGE_NOT_INSTALLED
;
655 pdata
.action
= OPKG_INSTALL
;
656 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
659 err
= opkg_upgrade_pkg (opkg
->conf
, pkg
);
660 /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
664 opkg_package_free (pdata
.package
);
667 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
668 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
669 case OPKG_INSTALL_ERR_DEPENDENCIES
:
670 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
671 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
672 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
673 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
674 case OPKG_INSTALL_ERR_SHA256
: return OPKG_SHA256_ERROR
;
675 default: return OPKG_UNKNOWN_ERROR
;
678 progress (pdata
, 75);
680 err
= opkg_configure_packages (opkg
->conf
, NULL
);
682 opkg_package_free (pdata
.package
);
683 return OPKG_UNKNOWN_ERROR
;
686 /* write out status files and file lists */
687 opkg_conf_write_status_files (opkg
->conf
);
688 pkg_write_changed_filelists (opkg
->conf
);
690 progress (pdata
, 100);
691 opkg_package_free (pdata
.package
);
696 opkg_upgrade_all (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
698 pkg_vec_t
*installed
;
702 opkg_progress_data_t pdata
;
704 pdata
.action
= OPKG_INSTALL
;
705 pdata
.package
= NULL
;
707 opkg_assert (opkg
!= NULL
);
710 installed
= pkg_vec_alloc ();
711 pkg_info_preinstall_check (opkg
->conf
);
713 pkg_hash_fetch_all_installed (&opkg
->conf
->pkg_hash
, installed
);
714 for (i
= 0; i
< installed
->len
; i
++)
716 pkg
= installed
->pkgs
[i
];
718 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
719 progress (pdata
, 99 * i
/ installed
->len
);
720 opkg_package_free (pdata
.package
);
722 err
+= opkg_upgrade_pkg (opkg
->conf
, pkg
);
724 pkg_vec_free (installed
);
729 err
= opkg_configure_packages (opkg
->conf
, NULL
);
733 pdata
.package
= NULL
;
734 progress (pdata
, 100);
739 opkg_update_package_lists (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
744 pkg_src_list_elt_t
*iter
;
746 int sources_list_count
, sources_done
;
747 opkg_progress_data_t pdata
;
749 opkg_assert (opkg
!= NULL
);
751 pdata
.action
= OPKG_DOWNLOAD
;
752 pdata
.package
= NULL
;
755 sprintf_alloc (&lists_dir
, "%s",
756 (opkg
->conf
->restrict_to_default_dest
)
757 ? opkg
->conf
->default_dest
->lists_dir
758 : opkg
->conf
->lists_dir
);
760 if (!file_is_dir (lists_dir
))
762 if (file_exists (lists_dir
))
764 /* XXX: Error: file exists but is not a directory */
769 err
= file_mkdir_hier (lists_dir
, 0755);
772 /* XXX: Error: failed to create directory */
778 tmp
= strdup ("/tmp/opkg.XXXXXX");
780 if (mkdtemp (tmp
) == NULL
)
782 /* XXX: Error: could not create temporary file name */
788 /* count the number of sources so we can give some progress updates */
789 sources_list_count
= 0;
791 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
793 sources_list_count
++;
796 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
798 char *url
, *list_file_name
= NULL
;
800 src
= (pkg_src_t
*)iter
->data
;
802 if (src
->extra_data
) /* debian style? */
803 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
804 src
->gzip
? "Packages.gz" : "Packages");
806 sprintf_alloc (&url
, "%s/%s", src
->value
, src
->gzip
? "Packages.gz" : "Packages");
808 sprintf_alloc (&list_file_name
, "%s/%s", lists_dir
, src
->name
);
812 struct _curl_cb_data cb_data
;
813 char *tmp_file_name
= NULL
;
815 sprintf_alloc (&tmp_file_name
, "%s/%s.gz", tmp
, src
->name
);
817 /* XXX: Note: downloading url */
819 cb_data
.cb
= progress_callback
;
820 cb_data
.progress_data
= &pdata
;
822 cb_data
.user_data
= user_data
;
823 cb_data
.start_range
= 100 * sources_done
/ sources_list_count
;
824 cb_data
.finish_range
= 100 * (sources_done
+ 1) / sources_list_count
;
826 err
= opkg_download (opkg
->conf
, url
, tmp_file_name
, (curl_progress_func
) curl_progress_cb
, &cb_data
);
830 /* XXX: Note: Inflating downloaded file */
831 in
= fopen (tmp_file_name
, "r");
832 out
= fopen (list_file_name
, "w");
841 unlink (tmp_file_name
);
843 free (tmp_file_name
);
846 err
= opkg_download (opkg
->conf
, url
, list_file_name
, NULL
, NULL
);
850 /* XXX: Error: download error */
851 result
= OPKG_DOWNLOAD_FAILED
;
855 #if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
856 if ( opkg
->conf
->check_signature
) {
858 /* download detached signitures to verify the package lists */
859 /* get the url for the sig file */
860 if (src
->extra_data
) /* debian style? */
861 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
864 sprintf_alloc (&url
, "%s/%s", src
->value
, "Packages.sig");
866 /* create filename for signature */
867 sprintf_alloc (&sig_file_name
, "%s/%s.sig", lists_dir
, src
->name
);
869 /* make sure there is no existing signature file */
870 unlink (sig_file_name
);
872 err
= opkg_download (opkg
->conf
, url
, sig_file_name
, NULL
, NULL
);
875 /* XXX: Warning: Download failed */
880 err
= opkg_verify_file (opkg
->conf
, list_file_name
, sig_file_name
);
883 /* XXX: Notice: Signature check passed */
887 /* XXX: Warning: Signature check failed */
890 free (sig_file_name
);
891 free (list_file_name
);
895 /* XXX: Note: Signature check for %s skipped because GPG support was not
896 * enabled in this build
901 progress (pdata
, 100 * sources_done
/ sources_list_count
);
908 /* Now re-read the package lists to update package hash tables. */
909 opkg_re_read_config_files (opkg
);
916 opkg_list_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
922 opkg_assert (callback
);
924 all
= pkg_vec_alloc ();
925 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
926 for (i
= 0; i
< all
->len
; i
++)
929 opkg_package_t
*package
;
933 package
= pkg_t_to_opkg_package_t (pkg
);
934 callback (opkg
, package
, user_data
);
935 opkg_package_free (package
);
944 opkg_list_upgradable_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
946 struct active_list
*head
;
947 struct active_list
*node
;
948 pkg_t
*old
=NULL
, *new = NULL
;
949 static opkg_package_t
* package
=NULL
;
953 opkg_assert (callback
);
955 /* ensure all data is valid */
956 pkg_info_preinstall_check (opkg
->conf
);
958 head
= prepare_upgrade_list(opkg
->conf
);
959 for (node
=active_list_next(head
, head
); node
; active_list_next(head
,node
)) {
960 old
= list_entry(node
, pkg_t
, list
);
961 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, old
->name
, NULL
);
962 package
= pkg_t_to_opkg_package_t (new);
963 callback (opkg
, package
, user_data
);
964 opkg_package_free (package
);
966 active_list_head_delete(head
);
971 opkg_find_package (opkg_t
*opkg
, const char *name
, const char *ver
, const char *arch
, const char *repo
)
974 opkg_package_t
*package
= NULL
;
976 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
980 all
= pkg_vec_alloc ();
981 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
982 for (i
= 0; i
< all
->len
; i
++)
990 if (sstrcmp (pkg
->name
, name
))
994 pkgv
= pkg_version_str_alloc (pkg
);
995 if (sstrcmp (pkgv
, ver
))
1002 /* check architecture */
1005 if (sstrcmp (pkg
->architecture
, arch
))
1009 /* check repository */
1012 if (sstrcmp (pkg
->src
->name
, repo
))
1017 package
= pkg_t_to_opkg_package_t (pkg
);
1027 #include <curl/curl.h>
1030 * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status.
1031 * @param opkg The opkg_t
1032 * @return return how many repositories cannot access. 0 means all okay.
1034 int opkg_repository_accessibility_check(opkg_t
*opkg
)
1036 pkg_src_list_elt_t
*iter
;
1037 str_list_elt_t
*iter1
;
1044 opkg_assert(opkg
!= NULL
);
1046 src
= str_list_alloc();
1048 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
1050 if (strstr(((pkg_src_t
*)iter
->data
)->value
, "://") &&
1051 index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/'))
1052 stmp
= strndup(((pkg_src_t
*)iter
->data
)->value
,
1053 (index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/') - ((pkg_src_t
*)iter
->data
)->value
)*sizeof(char));
1056 stmp
= strdup(((pkg_src_t
*)iter
->data
)->value
);
1058 for (iter1
= str_list_first(src
); iter1
; iter1
= str_list_next(src
, iter1
))
1060 if (strstr(iter1
->data
, stmp
))
1066 sprintf_alloc(&repo_ptr
, "%s/index.html",stmp
);
1069 str_list_append(src
, repo_ptr
);
1073 while (repositories
> 0)
1075 iter1
= str_list_pop(src
);
1078 err
= opkg_download(opkg
->conf
, iter1
->data
, "/dev/null", NULL
, NULL
);
1080 if (!(err
== CURLE_OK
||
1081 err
== CURLE_HTTP_RETURNED_ERROR
||
1082 err
== CURLE_FILE_COULDNT_READ_FILE
||
1083 err
== CURLE_REMOTE_FILE_NOT_FOUND
||
1084 err
== CURLE_TFTP_NOTFOUND
1091 str_list_elt_deinit(iter1
);