librazor/razor.h
author J. Ali Harlow <ali@juiblex.co.uk>
Thu May 14 05:55:19 2009 +0100 (2009-05-14)
changeset 367 e45f50e940b6
parent 361 2523d03a840e
child 368 ea743486ba6f
permissions -rw-r--r--
Order the installation and removal of packages correctly so scripts can run
     1 /*
     2  * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     3  * Copyright (C) 2008  Red Hat, Inc
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; either version 2 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along
    16  * with this program; if not, write to the Free Software Foundation, Inc.,
    17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
    19 
    20 #ifndef _RAZOR_H_
    21 #define _RAZOR_H_
    22 
    23 #include <stdint.h>
    24 
    25 enum razor_repo_file_type {
    26 	RAZOR_REPO_FILE_MAIN,
    27 	RAZOR_REPO_FILE_DETAILS,
    28 	RAZOR_REPO_FILE_FILES
    29 };
    30 
    31 enum razor_detail_type {
    32 	RAZOR_DETAIL_LAST = 0,	/* the sentinel */
    33 	RAZOR_DETAIL_NAME,
    34 	RAZOR_DETAIL_VERSION,
    35 	RAZOR_DETAIL_ARCH,
    36 	RAZOR_DETAIL_SUMMARY,
    37 	RAZOR_DETAIL_DESCRIPTION,
    38 	RAZOR_DETAIL_URL,
    39 	RAZOR_DETAIL_LICENSE
    40 };
    41 
    42 enum razor_property_flags {
    43 	RAZOR_PROPERTY_LESS		= 1 << 0,
    44 	RAZOR_PROPERTY_GREATER		= 1 << 1,
    45 	RAZOR_PROPERTY_EQUAL		= 1 << 2,
    46 	RAZOR_PROPERTY_RELATION_MASK	=
    47 		RAZOR_PROPERTY_LESS |
    48 		RAZOR_PROPERTY_GREATER |
    49 		RAZOR_PROPERTY_EQUAL,
    50 
    51 	RAZOR_PROPERTY_REQUIRES		= 0 << 3,
    52 	RAZOR_PROPERTY_PROVIDES		= 1 << 3,
    53 	RAZOR_PROPERTY_CONFLICTS	= 2 << 3,
    54 	RAZOR_PROPERTY_OBSOLETES	= 3 << 3,
    55 	RAZOR_PROPERTY_TYPE_MASK	= 3 << 3,
    56 		
    57 	RAZOR_PROPERTY_PRE		= 1 << 5,
    58 	RAZOR_PROPERTY_POST		= 1 << 6,
    59 	RAZOR_PROPERTY_PREUN		= 1 << 7,
    60 	RAZOR_PROPERTY_POSTUN		= 1 << 8
    61 };
    62 
    63 /**
    64  * SECTION:set
    65  * @title: Package Set
    66  * @short_description: Represents a set of packages and their metadata.
    67  *
    68  * This object represents a set of packages, their dependency
    69  * information, the file lists and a number of other details.
    70  **/
    71 
    72 struct razor_set;
    73 struct razor_package;
    74 struct razor_property;
    75 
    76 /**
    77  * razor_set_create:
    78  * 
    79  * Create a new #razor_set object.
    80  * 
    81  * Returns: the new #razor_set object.
    82  **/
    83 struct razor_set *razor_set_create_without_root(void);
    84 struct razor_set *razor_set_create(void);
    85 struct razor_set *razor_set_open(const char *filename);
    86 void razor_set_destroy(struct razor_set *set);
    87 int razor_set_write_to_fd(struct razor_set *set, int fd,
    88 			  enum razor_repo_file_type type);
    89 int razor_set_write(struct razor_set *set, const char *filename,
    90 		    enum razor_repo_file_type type);
    91 
    92 int razor_set_open_details(struct razor_set *set, const char *filename);
    93 int razor_set_open_files(struct razor_set *set, const char *filename);
    94 
    95 struct razor_package *
    96 razor_set_get_package(struct razor_set *set, const char *package);
    97 
    98 void
    99 razor_package_get_details(struct razor_set *set,
   100 			  struct razor_package *package, ...);
   101 
   102 
   103 /**
   104  * SECTION:iterator
   105  * @title: Iterators
   106  * @short_description: Objects for traversing packages or properties.
   107  *
   108  * The razor iterator objects provides a way to iterate through a set
   109  * of packages or properties.
   110  **/
   111 
   112 struct razor_package_iterator;
   113 
   114 /**
   115  * razor_package_iterator_create:
   116  * 
   117  * Create a new #razor_package_iterator object.
   118  * 
   119  * Returns: the new #razor_package_iterator object.
   120  **/
   121 
   122 struct razor_package_iterator *
   123 razor_package_iterator_create(struct razor_set *set);
   124 
   125 /**
   126  * razor_package_iterator_create_for_property:
   127  * 
   128  * Create a new #razor_package_iterator object for the packages that
   129  * own the given property.
   130  * 
   131  * Returns: the new #razor_package_iterator object.
   132  **/
   133 struct razor_package_iterator *
   134 razor_package_iterator_create_for_property(struct razor_set *set,
   135 					   struct razor_property *property);
   136 
   137 /**
   138  * razor_package_iterator_create_for_file:
   139  *
   140  * Create a new #razor_package_iterator object for the packages that
   141  * contain the given file name.
   142  *
   143  * Returns: the new #razor_package_iterator object.
   144  **/
   145 struct razor_package_iterator *
   146 razor_package_iterator_create_for_file(struct razor_set *set,
   147 				       const char *filename);
   148 
   149 int razor_package_iterator_next(struct razor_package_iterator *pi,
   150 				struct razor_package **package, ...);
   151 void razor_package_iterator_destroy(struct razor_package_iterator *pi);
   152 
   153 struct razor_package_query *
   154 razor_package_query_create(struct razor_set *set);
   155 void
   156 razor_package_query_add_package(struct razor_package_query *pq,
   157 				struct razor_package *p);
   158 void
   159 razor_package_query_add_iterator(struct razor_package_query *pq,
   160 				 struct razor_package_iterator *pi);
   161 struct razor_package_iterator *
   162 razor_package_query_finish(struct razor_package_query *pq);
   163 
   164 struct razor_property_iterator;
   165 struct razor_property_iterator *
   166 razor_property_iterator_create(struct razor_set *set,
   167 			       struct razor_package *package);
   168 int razor_property_iterator_next(struct razor_property_iterator *pi,
   169 				 struct razor_property **property,
   170 				 const char **name,
   171 				 uint32_t *flags,
   172 				 const char **version);
   173 void
   174 razor_property_iterator_destroy(struct razor_property_iterator *pi);
   175 
   176 struct razor_file_iterator;
   177 struct razor_file_iterator *
   178 razor_file_iterator_create(struct razor_set *set,
   179 			   struct razor_package *package);
   180 int razor_file_iterator_next(struct razor_file_iterator *fi,
   181 			     const char **name);
   182 void razor_file_iterator_destroy(struct razor_file_iterator *fi);
   183 
   184 void razor_set_list_files(struct razor_set *set, const char *prefix);
   185 void razor_set_list_package_files(struct razor_set *set,
   186 				  struct razor_package *package);
   187 
   188 enum razor_diff_action {
   189 	RAZOR_DIFF_ACTION_ADD,
   190 	RAZOR_DIFF_ACTION_REMOVE,
   191 };
   192 
   193 typedef void (*razor_diff_callback_t)(enum razor_diff_action action,
   194 				      struct razor_package *package,
   195 				      const char *name,
   196 				      const char *version,
   197 				      const char *arch,
   198 				      void *data);
   199 
   200 void
   201 razor_set_diff(struct razor_set *set, struct razor_set *upstream,
   202 	       razor_diff_callback_t callback, void *data);
   203 
   204 struct razor_install_iterator;
   205 
   206 enum razor_install_action {
   207 	RAZOR_INSTALL_ACTION_ADD,
   208 	RAZOR_INSTALL_ACTION_REMOVE
   209 };
   210 
   211 struct razor_install_iterator *
   212 razor_set_create_install_iterator(struct razor_set *set,
   213 				  struct razor_set *next);
   214 
   215 int razor_install_iterator_next(struct razor_install_iterator *ii,
   216 				struct razor_set **set,
   217 				struct razor_package **package,
   218 				enum razor_install_action *action,
   219 				int *count);
   220 
   221 void razor_install_iterator_destroy(struct razor_install_iterator *ii);
   222 
   223 /**
   224  * SECTION:transaction
   225  * @title: Transaction
   226  * @short_description: Create a new package set by merging two or more sets.
   227  *
   228  * The razor transaction object provides a way to create a new package set
   229  * from packages from one or more other package sets.
   230  **/
   231 
   232 struct razor_transaction *
   233 razor_transaction_create(struct razor_set *system, struct razor_set *upstream);
   234 void razor_transaction_install_package(struct razor_transaction *transaction,
   235 				       struct razor_package *package);
   236 void razor_transaction_remove_package(struct razor_transaction *transaction,
   237 				      struct razor_package *package);
   238 void razor_transaction_update_package(struct razor_transaction *trans,
   239 				      struct razor_package *package);
   240 void razor_transaction_update_all(struct razor_transaction *transaction);
   241 int razor_transaction_resolve(struct razor_transaction *trans);
   242 int razor_transaction_describe(struct razor_transaction *trans);
   243 struct razor_set *razor_transaction_finish(struct razor_transaction *trans);
   244 void razor_transaction_destroy(struct razor_transaction *trans);
   245 
   246 /* Temporary helper for test suite. */
   247 int razor_transaction_unsatisfied_property(struct razor_transaction *trans,
   248 					   const char *name,
   249 					   uint32_t flags,
   250 					   const char *version);
   251 
   252 /**
   253  * SECTION:rpm
   254  * @title: Razor RPM
   255  * @short_description: Operating on RPM files.
   256  *
   257  * Functions for open RPM files and extracting information and
   258  * installing or removing RPM files.
   259  **/
   260 
   261 struct razor_relocations;
   262 struct razor_rpm;
   263 
   264 struct razor_relocations *razor_relocations_create(void);
   265 void razor_relocations_add(struct razor_relocations *relocations,
   266 			   const char *oldpath, const char *newpath);
   267 void razor_relocations_set_rpm(struct razor_relocations *relocations,
   268 			       struct razor_rpm *rpm);
   269 const char *razor_relocations_apply(struct razor_relocations *relocations,
   270 				    const char *path);
   271 void razor_relocations_destroy(struct razor_relocations *relocations);
   272 
   273 struct razor_rpm *razor_rpm_open(const char *filename);
   274 void razor_rpm_set_relocations(struct razor_rpm *rpm,
   275 			       struct razor_relocations *relocations);
   276 int razor_rpm_install(struct razor_rpm *rpm, const char *root);
   277 int razor_rpm_close(struct razor_rpm *rpm);
   278 
   279 /**
   280  * SECTION:importer
   281  * @title: Importer
   282  * @short_description: A mechanism for building #razor_set objects
   283  *
   284  * The %razor_importer is a helper object for building a razor set
   285  * from external sources, like yum metadata, the RPM database or RPM
   286  * files.
   287  *
   288  * The importer is a stateful object; it has the notion of a current
   289  * package, and the caller can provide meta data such as properties,
   290  * files and similiar for the package as it becomes available.  Once a
   291  * package is fully described, the next pacakge can begin.  When all
   292  * packages have been described to the importer, the importer will
   293  * create a new %razor_set with the specified packages.
   294  *
   295  * A typical use
   296  * of the importer will follow this template:
   297  * |[
   298  * importer = razor_importer_create();
   299  *
   300  * while ( /<!-- -->* more packages to import *<!-- -->/; ) {
   301  *   /<!-- -->* get name, version and arch of next package *<!-- -->/
   302  *   razor_importer_begin_package(importer, name, version, arch);
   303  *   razor_importer_add_details(importer, summary, description, url, license);
   304  *
   305  *   while ( /<!-- -->* more properties to add *<!-- -->/ )
   306  *     razor_importer_add_property(importer, name, flags, version);
   307  *
   308  *   while ( /<!-- -->* [more files to add *<!-- -->/ )
   309  *     razor_importer_add_file(importer, name);
   310  *
   311  *   razor_importer_finish_package(importer);
   312  * }
   313  *
   314  * return razor_importer_finish(importer);
   315  * ]|
   316  **/
   317 struct razor_importer;
   318 
   319 struct razor_importer *razor_importer_create(void);
   320 void razor_importer_destroy(struct razor_importer *importer);
   321 void razor_importer_begin_package(struct razor_importer *importer,
   322 				  const char *name,
   323 				  const char *version,
   324 				  const char *arch);
   325 void razor_importer_add_details(struct razor_importer *importer,
   326 				const char *summary,
   327 				const char *description,
   328 				const char *url,
   329 				const char *license);
   330 void razor_importer_add_property(struct razor_importer *importer,
   331 				 const char *name,
   332 				 uint32_t flags,
   333 				 const char *version);
   334 void razor_importer_add_file(struct razor_importer *importer,
   335 			     const char *name);
   336 void razor_importer_finish_package(struct razor_importer *importer);
   337 
   338 int razor_importer_add_rpm(struct razor_importer *importer,
   339 			   struct razor_rpm *rpm);
   340 
   341 struct razor_set *razor_importer_finish(struct razor_importer *importer);
   342 
   343 struct razor_set *razor_set_create_from_yum(void);
   344 struct razor_set *razor_set_create_from_rpmdb(void);
   345 
   346 /**
   347  * SECTION:root
   348  * @title: Root
   349  * @short_description: Functions for accessing an install root.
   350  *
   351  * The #razor_root object encapsulate access to and locking of a razor
   352  * install root.
   353  **/
   354 struct razor_root;
   355 
   356 int razor_root_create(const char *root);
   357 struct razor_root *razor_root_open(const char *root);
   358 struct razor_set *razor_root_open_read_only(const char *root);
   359 struct razor_set *razor_root_get_system_set(struct razor_root *root);
   360 int razor_root_close(struct razor_root *root);
   361 void razor_root_update(struct razor_root *root, struct razor_set *next);
   362 int razor_root_commit(struct razor_root *root);
   363 
   364 
   365 /**
   366  * SECTION:misc
   367  * @title: Miscellaneous Functions
   368  * @short_description: Various helper functions
   369  *
   370  * Functions that doesn't fit anywhere else.
   371  **/
   372 
   373 const char *
   374 razor_property_relation_to_string(struct razor_property *p);
   375 const char *
   376 razor_property_type_to_string(struct razor_property *p);
   377 
   378 void razor_build_evr(char *evr_buf, int size, const char *epoch,
   379 		     const char *version, const char *release);
   380 int razor_versioncmp(const char *s1, const char *s2);
   381 
   382 void razor_disable_root_name_checks(int disable);
   383 
   384 void razor_set_lua_loader(const char *modname, void (*loader)());
   385 
   386 
   387 #endif /* _RAZOR_H_ */