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