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