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 default: return OPKG_UNKNOWN_ERROR
;
538 progress (pdata
, 75);
540 /* run configure scripts, etc. */
541 err
= opkg_configure_packages (opkg
->conf
, NULL
);
544 opkg_package_free (pdata
.package
);
545 return OPKG_UNKNOWN_ERROR
;
548 /* write out status files and file lists */
549 opkg_conf_write_status_files (opkg
->conf
);
550 pkg_write_changed_filelists (opkg
->conf
);
552 progress (pdata
, 100);
553 opkg_package_free (pdata
.package
);
558 opkg_remove_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
562 pkg_t
*pkg_to_remove
;
563 opkg_progress_data_t pdata
;
565 opkg_assert (opkg
!= NULL
);
566 opkg_assert (package_name
!= NULL
);
568 pkg_info_preinstall_check (opkg
->conf
);
570 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, package_name
);
574 /* XXX: Error: Package not installed. */
575 return OPKG_PACKAGE_NOT_INSTALLED
;
578 pdata
.action
= OPKG_REMOVE
;
579 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
583 if (pkg
->state_status
== SS_NOT_INSTALLED
)
585 /* XXX: Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
586 opkg_package_free (pdata
.package
);
587 return OPKG_PACKAGE_NOT_INSTALLED
;
589 progress (pdata
, 25);
591 if (opkg
->conf
->restrict_to_default_dest
)
593 pkg_to_remove
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
595 opkg
->conf
->default_dest
);
599 pkg_to_remove
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
, pkg
->name
);
603 progress (pdata
, 75);
605 err
= opkg_remove_pkg (opkg
->conf
, pkg_to_remove
, 0);
607 /* write out status files and file lists */
608 opkg_conf_write_status_files (opkg
->conf
);
609 pkg_write_changed_filelists (opkg
->conf
);
612 progress (pdata
, 100);
613 opkg_package_free (pdata
.package
);
614 return (err
) ? OPKG_UNKNOWN_ERROR
: OPKG_NO_ERROR
;
618 opkg_upgrade_package (opkg_t
*opkg
, const char *package_name
, opkg_progress_callback_t progress_callback
, void *user_data
)
622 opkg_progress_data_t pdata
;
626 opkg_assert (opkg
!= NULL
);
627 opkg_assert (package_name
!= NULL
);
629 pkg_info_preinstall_check (opkg
->conf
);
631 if (opkg
->conf
->restrict_to_default_dest
)
633 pkg
= pkg_hash_fetch_installed_by_name_dest (&opkg
->conf
->pkg_hash
,
635 opkg
->conf
->default_dest
);
638 /* XXX: Error: Package not installed in default_dest */
639 return OPKG_PACKAGE_NOT_INSTALLED
;
644 pkg
= pkg_hash_fetch_installed_by_name (&opkg
->conf
->pkg_hash
,
650 /* XXX: Error: Package not installed */
651 return OPKG_PACKAGE_NOT_INSTALLED
;
654 pdata
.action
= OPKG_INSTALL
;
655 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
658 err
= opkg_upgrade_pkg (opkg
->conf
, pkg
);
659 /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
663 opkg_package_free (pdata
.package
);
666 case OPKG_INSTALL_ERR_NOT_TRUSTED
: return OPKG_GPG_ERROR
;
667 case OPKG_INSTALL_ERR_DOWNLOAD
: return OPKG_DOWNLOAD_FAILED
;
668 case OPKG_INSTALL_ERR_DEPENDENCIES
:
669 case OPKG_INSTALL_ERR_CONFLICTS
: return OPKG_DEPENDENCIES_FAILED
;
670 case OPKG_INSTALL_ERR_ALREADY_INSTALLED
: return OPKG_PACKAGE_ALREADY_INSTALLED
;
671 case OPKG_INSTALL_ERR_SIGNATURE
: return OPKG_GPG_ERROR
;
672 case OPKG_INSTALL_ERR_MD5
: return OPKG_MD5_ERROR
;
673 default: return OPKG_UNKNOWN_ERROR
;
676 progress (pdata
, 75);
678 err
= opkg_configure_packages (opkg
->conf
, NULL
);
680 opkg_package_free (pdata
.package
);
681 return OPKG_UNKNOWN_ERROR
;
684 /* write out status files and file lists */
685 opkg_conf_write_status_files (opkg
->conf
);
686 pkg_write_changed_filelists (opkg
->conf
);
688 progress (pdata
, 100);
689 opkg_package_free (pdata
.package
);
694 opkg_upgrade_all (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
696 pkg_vec_t
*installed
;
700 opkg_progress_data_t pdata
;
702 pdata
.action
= OPKG_INSTALL
;
703 pdata
.package
= NULL
;
705 opkg_assert (opkg
!= NULL
);
708 installed
= pkg_vec_alloc ();
709 pkg_info_preinstall_check (opkg
->conf
);
711 pkg_hash_fetch_all_installed (&opkg
->conf
->pkg_hash
, installed
);
712 for (i
= 0; i
< installed
->len
; i
++)
714 pkg
= installed
->pkgs
[i
];
716 pdata
.package
= pkg_t_to_opkg_package_t (pkg
);
717 progress (pdata
, 99 * i
/ installed
->len
);
718 opkg_package_free (pdata
.package
);
720 err
+= opkg_upgrade_pkg (opkg
->conf
, pkg
);
722 pkg_vec_free (installed
);
727 err
= opkg_configure_packages (opkg
->conf
, NULL
);
731 pdata
.package
= NULL
;
732 progress (pdata
, 100);
737 opkg_update_package_lists (opkg_t
*opkg
, opkg_progress_callback_t progress_callback
, void *user_data
)
742 pkg_src_list_elt_t
*iter
;
744 int sources_list_count
, sources_done
;
745 opkg_progress_data_t pdata
;
747 opkg_assert (opkg
!= NULL
);
749 pdata
.action
= OPKG_DOWNLOAD
;
750 pdata
.package
= NULL
;
753 sprintf_alloc (&lists_dir
, "%s",
754 (opkg
->conf
->restrict_to_default_dest
)
755 ? opkg
->conf
->default_dest
->lists_dir
756 : opkg
->conf
->lists_dir
);
758 if (!file_is_dir (lists_dir
))
760 if (file_exists (lists_dir
))
762 /* XXX: Error: file exists but is not a directory */
767 err
= file_mkdir_hier (lists_dir
, 0755);
770 /* XXX: Error: failed to create directory */
776 tmp
= strdup ("/tmp/opkg.XXXXXX");
778 if (mkdtemp (tmp
) == NULL
)
780 /* XXX: Error: could not create temporary file name */
786 /* count the number of sources so we can give some progress updates */
787 sources_list_count
= 0;
789 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
791 sources_list_count
++;
794 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
796 char *url
, *list_file_name
= NULL
;
798 src
= (pkg_src_t
*)iter
->data
;
800 if (src
->extra_data
) /* debian style? */
801 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
802 src
->gzip
? "Packages.gz" : "Packages");
804 sprintf_alloc (&url
, "%s/%s", src
->value
, src
->gzip
? "Packages.gz" : "Packages");
806 sprintf_alloc (&list_file_name
, "%s/%s", lists_dir
, src
->name
);
810 struct _curl_cb_data cb_data
;
811 char *tmp_file_name
= NULL
;
813 sprintf_alloc (&tmp_file_name
, "%s/%s.gz", tmp
, src
->name
);
815 /* XXX: Note: downloading url */
817 cb_data
.cb
= progress_callback
;
818 cb_data
.progress_data
= &pdata
;
820 cb_data
.user_data
= user_data
;
821 cb_data
.start_range
= 100 * sources_done
/ sources_list_count
;
822 cb_data
.finish_range
= 100 * (sources_done
+ 1) / sources_list_count
;
824 err
= opkg_download (opkg
->conf
, url
, tmp_file_name
, (curl_progress_func
) curl_progress_cb
, &cb_data
);
828 /* XXX: Note: Inflating downloaded file */
829 in
= fopen (tmp_file_name
, "r");
830 out
= fopen (list_file_name
, "w");
839 unlink (tmp_file_name
);
841 free (tmp_file_name
);
844 err
= opkg_download (opkg
->conf
, url
, list_file_name
, NULL
, NULL
);
848 /* XXX: Error: download error */
849 result
= OPKG_DOWNLOAD_FAILED
;
854 if ( opkg
->conf
->check_signature
) {
856 /* download detached signitures to verify the package lists */
857 /* get the url for the sig file */
858 if (src
->extra_data
) /* debian style? */
859 sprintf_alloc (&url
, "%s/%s/%s", src
->value
, src
->extra_data
,
862 sprintf_alloc (&url
, "%s/%s", src
->value
, "Packages.sig");
864 /* create filename for signature */
865 sprintf_alloc (&sig_file_name
, "%s/%s.sig", lists_dir
, src
->name
);
867 /* make sure there is no existing signature file */
868 unlink (sig_file_name
);
870 err
= opkg_download (opkg
->conf
, url
, sig_file_name
, NULL
, NULL
);
873 /* XXX: Warning: Download failed */
878 err
= opkg_verify_file (opkg
->conf
, list_file_name
, sig_file_name
);
881 /* XXX: Notice: Signature check passed */
885 /* XXX: Warning: Signature check failed */
888 free (sig_file_name
);
889 free (list_file_name
);
893 /* XXX: Note: Signature check for %s skipped because GPG support was not
894 * enabled in this build
899 progress (pdata
, 100 * sources_done
/ sources_list_count
);
906 /* Now re-read the package lists to update package hash tables. */
907 opkg_re_read_config_files (opkg
);
914 opkg_list_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
920 opkg_assert (callback
);
922 all
= pkg_vec_alloc ();
923 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
924 for (i
= 0; i
< all
->len
; i
++)
927 opkg_package_t
*package
;
931 package
= pkg_t_to_opkg_package_t (pkg
);
932 callback (opkg
, package
, user_data
);
933 opkg_package_free (package
);
942 opkg_list_upgradable_packages (opkg_t
*opkg
, opkg_package_callback_t callback
, void *user_data
)
944 struct active_list
*head
;
945 struct active_list
*node
;
946 pkg_t
*old
=NULL
, *new = NULL
;
947 static opkg_package_t
* package
=NULL
;
951 opkg_assert (callback
);
953 /* ensure all data is valid */
954 pkg_info_preinstall_check (opkg
->conf
);
956 head
= prepare_upgrade_list(opkg
->conf
);
957 for (node
=active_list_next(head
, head
); node
; active_list_next(head
,node
)) {
958 old
= list_entry(node
, pkg_t
, list
);
959 new = pkg_hash_fetch_best_installation_candidate_by_name(opkg
->conf
, old
->name
, NULL
);
960 package
= pkg_t_to_opkg_package_t (new);
961 callback (opkg
, package
, user_data
);
962 opkg_package_free (package
);
964 active_list_head_delete(head
);
969 opkg_find_package (opkg_t
*opkg
, const char *name
, const char *ver
, const char *arch
, const char *repo
)
972 opkg_package_t
*package
= NULL
;
974 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
978 all
= pkg_vec_alloc ();
979 pkg_hash_fetch_available (&opkg
->conf
->pkg_hash
, all
);
980 for (i
= 0; i
< all
->len
; i
++)
988 if (sstrcmp (pkg
->name
, name
))
992 pkgv
= pkg_version_str_alloc (pkg
);
993 if (sstrcmp (pkgv
, ver
))
1000 /* check architecture */
1003 if (sstrcmp (pkg
->architecture
, arch
))
1007 /* check repository */
1010 if (sstrcmp (pkg
->src
->name
, repo
))
1015 package
= pkg_t_to_opkg_package_t (pkg
);
1025 #include <curl/curl.h>
1028 * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status.
1029 * @param opkg The opkg_t
1030 * @return return how many repositories cannot access. 0 means all okay.
1032 int opkg_repository_accessibility_check(opkg_t
*opkg
)
1034 pkg_src_list_elt_t
*iter
;
1035 str_list_elt_t
*iter1
;
1042 opkg_assert(opkg
!= NULL
);
1044 src
= str_list_alloc();
1046 list_for_each_entry(iter
, &opkg
->conf
->pkg_src_list
.head
, node
)
1048 if (strstr(((pkg_src_t
*)iter
->data
)->value
, "://") &&
1049 index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/'))
1050 stmp
= strndup(((pkg_src_t
*)iter
->data
)->value
,
1051 (index(strstr(((pkg_src_t
*)iter
->data
)->value
, "://") + 3, '/') - ((pkg_src_t
*)iter
->data
)->value
)*sizeof(char));
1054 stmp
= strdup(((pkg_src_t
*)iter
->data
)->value
);
1056 for (iter1
= str_list_first(src
); iter1
; iter1
= str_list_next(src
, iter1
))
1058 if (strstr(iter1
->data
, stmp
))
1064 sprintf_alloc(&repo_ptr
, "%s/index.html",stmp
);
1067 str_list_append(src
, repo_ptr
);
1071 while (repositories
> 0)
1073 iter1
= str_list_pop(src
);
1076 err
= opkg_download(opkg
->conf
, iter1
->data
, "/dev/null", NULL
, NULL
);
1078 if (!(err
== CURLE_OK
||
1079 err
== CURLE_HTTP_RETURNED_ERROR
||
1080 err
== CURLE_FILE_COULDNT_READ_FILE
||
1081 err
== CURLE_REMOTE_FILE_NOT_FOUND
||
1082 err
== CURLE_TFTP_NOTFOUND
1089 str_list_elt_deinit(iter1
);