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_overwrite
= c
->force_overwrite
;
253 a
->force_downgrade
= c
->force_downgrade
;
254 a
->force_reinstall
= c
->force_reinstall
;
255 a
->force_removal_of_dependent_packages
= c
->force_removal_of_dependent_packages
;
256 a
->force_removal_of_essential_packages
= c
->force_removal_of_essential_packages
;
257 a
->nodeps
= c
->nodeps
;
258 a
->noaction
= c
->noaction
;
259 a
->query_all
= c
->query_all
;
260 a
->verbosity
= c
->verbosity
;
264 if (a
->offline_root
) free (a
->offline_root
);
265 a
->offline_root
= strdup (c
->offline_root
);
268 if (c
->offline_root_pre_script_cmd
)
270 if (a
->offline_root_pre_script_cmd
) free (a
->offline_root_pre_script_cmd
);
271 a
->offline_root_pre_script_cmd
= strdup (c
->offline_root_pre_script_cmd
);
274 if (c
->offline_root_post_script_cmd
)
276 if (a
->offline_root_post_script_cmd
) free (a
->offline_root_post_script_cmd
);
277 a
->offline_root_post_script_cmd
= strdup (c
->offline_root_post_script_cmd
);
283 a
->cache
= strdup(c
->cache
);
286 /* throw away old opkg_conf and start again */
287 opkg_conf_deinit (opkg
->conf
);
288 opkg_conf_init (opkg
->conf
, opkg
->args
);
290 free (opkg
->options
);
291 opkg_init_options_array (opkg
->conf
, &opkg
->options
);
297 opkg_get_option (opkg_t
*opkg
, char *option
, void **value
)
300 opkg_option_t
*options
;
302 opkg_assert (opkg
!= NULL
);
303 opkg_assert (option
!= NULL
);
304 opkg_assert (value
!= NULL
);
306 options
= opkg
->options
;
308 /* look up the option
309 * TODO: this would be much better as a hash table
311 while (options
[i
].name
)
313 if (strcmp (options
[i
].name
, option
) != 0)
321 switch (options
[i
].type
)
323 case OPKG_OPT_TYPE_BOOL
:
324 *((int *) value
) = *((int *) options
[i
].value
);
327 case OPKG_OPT_TYPE_INT
:
328 *((int *) value
) = *((int *) options
[i
].value
);
331 case OPKG_OPT_TYPE_STRING
:
332 *((char **)value
) = strdup (options
[i
].value
);
339 opkg_set_option (opkg_t
*opkg
, char *option
, void *value
)
341 int i
= 0, found
= 0;
342 opkg_option_t
*options
;
344 opkg_assert (opkg
!= NULL
);
345 opkg_assert (option
!= NULL
);
346 opkg_assert (value
!= NULL
);
348 options
= opkg
->options
;
350 /* look up the option
351 * TODO: this would be much better as a hash table
353 while (options
[i
].name
)
355 if (strcmp (options
[i
].name
, option
) == 0)
365 /* XXX: Warning: Option not found */
370 switch (options
[i
].type
)
372 case OPKG_OPT_TYPE_BOOL
:
373 if (*((int *) value
) == 0)
374 *((int *)options
[i
].value
) = 0;
376 *((int *)options
[i
].value
) = 1;
379 case OPKG_OPT_TYPE_INT
:
380 *((int *) options
[i
].value
) = *((int *) value
);
383 case OPKG_OPT_TYPE_STRING
:
384 *((char **)options
[i
].value
) = strdup (value
);
391 * @brief libopkg API: Install package
392 * @param opkg Then opkg handler
393 * @param package_name The name of package in which is going to install
394 * @param progress_callback The callback function that report the status to caller.
397 opkg_install_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
400 char *stripped_filename
;
401 opkg_progress_data_t pdata
;
403 pkg_vec_t
*deps
, *all
;
405 char **unresolved
= NULL
;
407 opkg_assert (opkg
!= NULL
);
408 opkg_assert (package_name
!= NULL
);
411 pkg_info_preinstall_check (opkg
->conf
);
414 /* check to ensure package is not already installed */
415 old
= pkg_hash_fetch_installed_by_name(&opkg
->conf
->pkg_hash
, package_name
);
418 /* XXX: Error: Package is already installed. */
419 return OPKG_PACKAGE_ALREADY_INSTALLED
;
422 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, package_name
, NULL
);
425 /* XXX: Error: Could not find package to install */
426 return OPKG_PACKAGE_NOT_FOUND
;
429 new->state_flag
|= SF_USER
;
431 pdata
.action
= OPKG_INSTALL
;
432 pdata
.package
= pkg_t_to_opkg_package_t (new);
436 /* find dependancies and download them */
437 deps
= pkg_vec_alloc ();
438 /* this function does not return the original package, so we insert it later */
439 ndepends
= pkg_hash_fetch_unsatisfied_dependencies (opkg
->conf
, new, deps
, &unresolved
);
442 /* XXX: Error: Could not satisfy dependencies */
444 return OPKG_DEPENDENCIES_FAILED
;
447 /* insert the package we are installing so that we download it */
448 pkg_vec_insert (deps
, new);
450 /* download package and dependancies */
451 for (i
= 0; i
< deps
->len
; i
++)
454 struct _curl_cb_data cb_data
;
458 if (pkg
->local_filename
)
461 opkg_package_free (pdata
.package
);
462 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
463 pdata
.action
= OPKG_DOWNLOAD
;
465 if (pkg
->src
== NULL
)
467 /* XXX: Error: Package not available from any configured src */
468 return OPKG_PACKAGE_NOT_AVAILABLE
;
471 sprintf_alloc(&url
, "%s/%s", pkg
->src
->value
, pkg
->filename
);
473 /* Get the filename part, without any directory */
474 stripped_filename
= strrchr(pkg
->filename
, '/');
475 if ( ! stripped_filename
)
476 stripped_filename
= pkg
->filename
;
478 sprintf_alloc(&pkg
->local_filename
, "%s/%s", opkg
->conf
->tmp_dir
, stripped_filename
);
480 cb_data
.cb
= progress_callback
;
481 cb_data
.progress_data
= &pdata
;
483 cb_data
.user_data
= user_data
;
484 /* 75% of "install" progress is for downloading */
485 cb_data
.start_range
= 75 * i
/ deps
->len
;
486 cb_data
.finish_range
= 75 * (i
+ 1) / deps
->len
;
488 err
= opkg_download(opkg
->conf
, url
, pkg
->local_filename
,
489 (curl_progress_func
) curl_progress_cb
, &cb_data
);
495 opkg_package_free (pdata
.package
);
496 return OPKG_DOWNLOAD_FAILED
;
502 /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
503 all
= pkg_vec_alloc ();
504 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
505 for (i
= 0; i
< all
->len
; i
++)
507 all
->pkgs
[i
]->parent
->dependencies_checked
= 0;
512 /* 75% of "install" progress is for downloading */
513 opkg_package_free (pdata
.package
);
514 pdata
.package
= pkg_t_to_opkg_package_t (new);
515 pdata
.action
= OPKG_INSTALL
;
516 progress (pdata
, 75);
518 /* unpack the package */
519 err
= opkg_install_pkg(opkg
->conf
, new, 0);
523 opkg_package_free (pdata
.package
);
526 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
527 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
528 case OPKG_INSTALL_ERR_DEPENDENCIES
:
529 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
530 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
531 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
532 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
533 default: return OPKG_UNKNOWN_ERROR
;
537 progress (pdata
, 75);
539 /* run configure scripts, etc. */
540 err
= opkg_configure_packages (opkg
->conf
, NULL
);
543 opkg_package_free (pdata
.package
);
544 return OPKG_UNKNOWN_ERROR
;
547 /* write out status files and file lists */
548 opkg_conf_write_status_files (opkg
->conf
);
549 pkg_write_changed_filelists (opkg
->conf
);
551 progress (pdata
, 100);
552 opkg_package_free (pdata
.package
);
557 opkg_remove_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
561 pkg_t
*pkg_to_remove
;
562 opkg_progress_data_t pdata
;
564 opkg_assert (opkg
!= NULL
);
565 opkg_assert (package_name
!= NULL
);
567 pkg_info_preinstall_check (opkg
->conf
);
569 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, package_name
);
573 /* XXX: Error: Package not installed. */
574 return OPKG_PACKAGE_NOT_INSTALLED
;
577 pdata
.action
= OPKG_REMOVE
;
578 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
582 if (pkg
->state_status
== SS_NOT_INSTALLED
)
584 /* XXX: Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
585 opkg_package_free (pdata
.package
);
586 return OPKG_PACKAGE_NOT_INSTALLED
;
588 progress (pdata
, 25);
590 if (opkg
->conf
->restrict_to_default_dest
)
592 pkg_to_remove
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
594 opkg
->conf
->default_dest
);
598 pkg_to_remove
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, pkg
->name
);
602 progress (pdata
, 75);
604 err
= opkg_remove_pkg (opkg
->conf
, pkg_to_remove
, 0);
606 /* write out status files and file lists */
607 opkg_conf_write_status_files (opkg
->conf
);
608 pkg_write_changed_filelists (opkg
->conf
);
611 progress (pdata
, 100);
612 opkg_package_free (pdata
.package
);
613 return (err
) ? OPKG_UNKNOWN_ERROR
: OPKG_NO_ERROR
;
617 opkg_upgrade_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
621 opkg_progress_data_t pdata
;
625 opkg_assert (opkg
!= NULL
);
626 opkg_assert (package_name
!= NULL
);
628 pkg_info_preinstall_check (opkg
->conf
);
630 if (opkg
->conf
->restrict_to_default_dest
)
632 pkg
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
634 opkg
->conf
->default_dest
);
637 /* XXX: Error: Package not installed in default_dest */
638 return OPKG_PACKAGE_NOT_INSTALLED
;
643 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
,
649 /* XXX: Error: Package not installed */
650 return OPKG_PACKAGE_NOT_INSTALLED
;
653 pdata
.action
= OPKG_INSTALL
;
654 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
657 err
= opkg_upgrade_pkg (opkg
->conf
, pkg
);
658 /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
662 opkg_package_free (pdata
.package
);
665 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
666 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
667 case OPKG_INSTALL_ERR_DEPENDENCIES
:
668 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
669 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
670 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
671 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
672 default: return OPKG_UNKNOWN_ERROR
;
675 progress (pdata
, 75);
677 err
= opkg_configure_packages (opkg
->conf
, NULL
);
679 opkg_package_free (pdata
.package
);
680 return OPKG_UNKNOWN_ERROR
;
683 /* write out status files and file lists */
684 opkg_conf_write_status_files (opkg
->conf
);
685 pkg_write_changed_filelists (opkg
->conf
);
687 progress (pdata
, 100);
688 opkg_package_free (pdata
.package
);
693 opkg_upgrade_all (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
695 pkg_vec_t
*installed
;
699 opkg_progress_data_t pdata
;
701 pdata
.action
= OPKG_INSTALL
;
702 pdata
.package
= NULL
;
704 opkg_assert (opkg
!= NULL
);
707 installed
= pkg_vec_alloc ();
708 pkg_info_preinstall_check (opkg
->conf
);
710 pkg_hash_fetch_all_installed (&opkg
->conf
->pkg_hash
, installed
);
711 for (i
= 0; i
< installed
->len
; i
++)
713 pkg
= installed
->pkgs
[i
];
715 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
716 progress (pdata
, 99 * i
/ installed
->len
);
717 opkg_package_free (pdata
.package
);
719 err
+= opkg_upgrade_pkg (opkg
->conf
, pkg
);
721 pkg_vec_free (installed
);
726 err
= opkg_configure_packages (opkg
->conf
, NULL
);
730 pdata
.package
= NULL
;
731 progress (pdata
, 100);
736 opkg_update_package_lists (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
741 pkg_src_list_elt_t
*iter
;
743 int sources_list_count
, sources_done
;
744 opkg_progress_data_t pdata
;
746 opkg_assert (opkg
!= NULL
);
748 pdata
.action
= OPKG_DOWNLOAD
;
749 pdata
.package
= NULL
;
752 sprintf_alloc (&lists_dir
, "%s",
753 (opkg
->conf
->restrict_to_default_dest
)
754 ? opkg
->conf
->default_dest
->lists_dir
755 : opkg
->conf
->lists_dir
);
757 if (!file_is_dir (lists_dir
))
759 if (file_exists (lists_dir
))
761 /* XXX: Error: file exists but is not a directory */
766 err
= file_mkdir_hier (lists_dir
, 0755);
769 /* XXX: Error: failed to create directory */
775 tmp
= strdup ("/tmp/opkg.XXXXXX");
777 if (mkdtemp (tmp
) == NULL
)
779 /* XXX: Error: could not create temporary file name */
785 /* count the number of sources so we can give some progress updates */
786 sources_list_count
= 0;
788 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
790 sources_list_count
++;
793 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
795 char *url
, *list_file_name
= NULL
;
797 src
= (pkg_src_t
*)iter
->data
;
799 if (src
->extra_data
) /* debian style? */
800 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
801 src
->gzip
? "Packages.gz" : "Packages");
803 sprintf_alloc (&url
, "%s/%s", src
->value
, src
->gzip
? "Packages.gz" : "Packages");
805 sprintf_alloc (&list_file_name
, "%s/%s", lists_dir
, src
->name
);
809 struct _curl_cb_data cb_data
;
810 char *tmp_file_name
= NULL
;
812 sprintf_alloc (&tmp_file_name
, "%s/%s.gz", tmp
, src
->name
);
814 /* XXX: Note: downloading url */
816 cb_data
.cb
= progress_callback
;
817 cb_data
.progress_data
= &pdata
;
819 cb_data
.user_data
= user_data
;
820 cb_data
.start_range
= 100 * sources_done
/ sources_list_count
;
821 cb_data
.finish_range
= 100 * (sources_done
+ 1) / sources_list_count
;
823 err
= opkg_download (opkg
->conf
, url
, tmp_file_name
, (curl_progress_func
) curl_progress_cb
, &cb_data
);
827 /* XXX: Note: Inflating downloaded file */
828 in
= fopen (tmp_file_name
, "r");
829 out
= fopen (list_file_name
, "w");
838 unlink (tmp_file_name
);
840 free (tmp_file_name
);
843 err
= opkg_download (opkg
->conf
, url
, list_file_name
, NULL
, NULL
);
847 /* XXX: Error: download error */
848 result
= OPKG_DOWNLOAD_FAILED
;
854 /* download detached signitures to verify the package lists */
855 /* get the url for the sig file */
856 if (src
->extra_data
) /* debian style? */
857 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
860 sprintf_alloc (&url
, "%s/%s", src
->value
, "Packages.sig");
862 /* create filename for signature */
863 sprintf_alloc (&sig_file_name
, "%s/%s.sig", lists_dir
, src
->name
);
865 /* make sure there is no existing signature file */
866 unlink (sig_file_name
);
868 err
= opkg_download (opkg
->conf
, url
, sig_file_name
, NULL
, NULL
);
871 /* XXX: Warning: Download failed */
876 err
= opkg_verify_file (opkg
->conf
, list_file_name
, sig_file_name
);
879 /* XXX: Notice: Signature check passed */
883 /* XXX: Warning: Signature check failed */
886 free (sig_file_name
);
887 free (list_file_name
);
890 /* XXX: Note: Signature check for %s skipped because GPG support was not
891 * enabled in this build
896 progress (pdata
, 100 * sources_done
/ sources_list_count
);
903 /* Now re-read the package lists to update package hash tables. */
904 opkg_re_read_config_files (opkg
);
911 opkg_list_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
917 opkg_assert (callback
);
919 all
= pkg_vec_alloc ();
920 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
921 for (i
= 0; i
< all
->len
; i
++)
924 opkg_package_t
*package
;
928 package
= pkg_t_to_opkg_package_t (pkg
);
929 callback (opkg
, package
, user_data
);
930 opkg_package_free (package
);
939 opkg_list_upgradable_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
941 struct active_list
*head
;
942 struct active_list
*node
;
943 pkg_t
*old
=NULL
, *new = NULL
;
944 static opkg_package_t
* package
=NULL
;
948 opkg_assert (callback
);
950 /* ensure all data is valid */
951 pkg_info_preinstall_check (opkg
->conf
);
953 head
= prepare_upgrade_list(opkg
->conf
);
954 for (node
=active_list_next(head
, head
); node
; active_list_next(head
,node
)) {
955 old
= list_entry(node
, pkg_t
, list
);
956 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, old
->name
, NULL
);
957 package
= pkg_t_to_opkg_package_t (new);
958 callback (opkg
, package
, user_data
);
959 opkg_package_free (package
);
961 active_list_head_delete(head
);
966 opkg_find_package (opkg_t
*opkg
, const char *name
, const char *ver
, const char *arch
, const char *repo
)
969 opkg_package_t
*package
= NULL
;
971 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
975 all
= pkg_vec_alloc ();
976 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
977 for (i
= 0; i
< all
->len
; i
++)
985 if (sstrcmp (pkg
->name
, name
))
989 pkgv
= pkg_version_str_alloc (pkg
);
990 if (sstrcmp (pkgv
, ver
))
997 /* check architecture */
1000 if (sstrcmp (pkg
->architecture
, arch
))
1004 /* check repository */
1007 if (sstrcmp (pkg
->src
->name
, repo
))
1012 package
= pkg_t_to_opkg_package_t (pkg
);
1022 #include <curl/curl.h>
1025 * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status.
1026 * @param opkg The opkg_t
1027 * @return return how many repositories cannot access. 0 means all okay.
1029 int opkg_repository_accessibility_check(opkg_t
*opkg
)
1031 pkg_src_list_elt_t
*iter
;
1032 str_list_elt_t
*iter1
;
1039 opkg_assert(opkg
!= NULL
);
1041 src
= str_list_alloc();
1043 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
1045 if (strstr(((pkg_src_t
*)iter
->data
)->value
, "://") &&
1046 index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/'))
1047 stmp
= strndup(((pkg_src_t
*)iter
->data
)->value
,
1048 (index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/') - ((pkg_src_t
*)iter
->data
)->value
)*sizeof(char));
1051 stmp
= strdup(((pkg_src_t
*)iter
->data
)->value
);
1053 for (iter1
= str_list_first(src
); iter1
; iter1
= str_list_next(src
, iter1
))
1055 if (strstr(iter1
->data
, stmp
))
1061 sprintf_alloc(&repo_ptr
, "%s/index.html",stmp
);
1064 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
);