1.1 --- a/librazor/razor.h Thu Aug 13 07:14:51 2009 +0100
1.2 +++ b/librazor/razor.h Thu Nov 10 10:35:21 2011 +0000
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
1.6 * Copyright (C) 2008 Red Hat, Inc
1.7 - * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
1.8 + * Copyright (C) 2009, 2011 J. Ali Harlow <ali@juiblex.co.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or modify
1.11 * it under the terms of the GNU General Public License as published by
1.12 @@ -22,6 +22,21 @@
1.13 #define _RAZOR_H_
1.14
1.15 #include <stdint.h>
1.16 +#include <sys/types.h>
1.17 +
1.18 +/* GCC extensions */
1.19 +#if defined(__GNUC__)
1.20 +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
1.21 +#define RAZOR_MALLOC __attribute__((__malloc__))
1.22 +#else
1.23 +#define RAZOR_MALLOC
1.24 +#endif
1.25 +#if __GNUC__ >= 4
1.26 +#define RAZOR_NULL_TERMINATED __attribute__ ((__sentinel__))
1.27 +#else
1.28 +#define RAZOR_NULL_TERMINATED
1.29 +#endif
1.30 +#endif /* __GNUC__ */
1.31
1.32 enum razor_section_type {
1.33 RAZOR_SECTION_MAIN = 0x01,
1.34 @@ -30,6 +45,14 @@
1.35 RAZOR_SECTION_ALL = 0x07
1.36 };
1.37
1.38 +enum razor_stage_type {
1.39 + RAZOR_STAGE_SCRIPTS_PRE = 0x1,
1.40 + RAZOR_STAGE_FILES = 0x2,
1.41 + RAZOR_STAGE_SCRIPTS_POST = 0x4,
1.42 + RAZOR_STAGE_SCRIPTS = 0x5,
1.43 + RAZOR_STAGE_ALL = 0x7
1.44 +};
1.45 +
1.46 enum razor_detail_type {
1.47 RAZOR_DETAIL_LAST = 0, /* the sentinel */
1.48 RAZOR_DETAIL_NAME,
1.49 @@ -73,6 +96,85 @@
1.50 };
1.51
1.52 /**
1.53 + * SECTION:atomic
1.54 + * @title: Atomic transactions
1.55 + * @short_description: File-based transactions that shouldn't half-succeed
1.56 + *
1.57 + * This is a helper object for issuing a sequence of file-based actions
1.58 + * that should either all succeed or all fail.
1.59 + *
1.60 + * Note that currently only Windows 7 has a native implementation and that
1.61 + * the fallback implementation will not rollback even if an error does occur.
1.62 + * This could (and should) be improved.
1.63 + **/
1.64 +struct razor_atomic;
1.65 +
1.66 +struct razor_atomic *razor_atomic_open(const char *description);
1.67 +int razor_atomic_commit(struct razor_atomic *atomic);
1.68 +const char *razor_atomic_get_error_msg(struct razor_atomic *atomic);
1.69 +void razor_atomic_destroy(struct razor_atomic *atomic);
1.70 +
1.71 +/**
1.72 + * razor_atomic_make_dirs
1.73 + *
1.74 + * Create all sub-directories leading up to path. We know root exists
1.75 + * and is a dir, root does not end in a '/', and path either has a
1.76 + * leading '/' or (on MS-Windows only) root is the empty string
1.77 + * and path starts with drive (eg., "c:/windows").
1.78 + * Note: path itself is not created, only the directory in which it
1.79 + * (would) exist.
1.80 + *
1.81 + * Returns: non-zero on error.
1.82 + **/
1.83 +int razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root,
1.84 + const char *path);
1.85 +int razor_atomic_remove(struct razor_atomic *atomic, const char *path);
1.86 +int razor_atomic_rename_file(struct razor_atomic *atomic, const char *oldpath,
1.87 + const char *newpath);
1.88 +
1.89 +/**
1.90 + * razor_atomic_create_dir
1.91 + *
1.92 + * Create a directory, replacing any existing object at this path except
1.93 + * an existing directory (which is not counted as a error).
1.94 + *
1.95 + * Returns: non-zero on error.
1.96 + */
1.97 +int razor_atomic_create_dir(struct razor_atomic *atomic, const char *dirname,
1.98 + mode_t mode);
1.99 +
1.100 +/**
1.101 + * razor_atomic_create_symlink
1.102 + *
1.103 + * Create a symbolic link, replacing any existing object at this path except
1.104 + * a non-empty directory.
1.105 + *
1.106 + * Note: This function will always fail on platforms that don't support
1.107 + * symbolic links.
1.108 + *
1.109 + * Returns: non-zero on error.
1.110 + */
1.111 +int razor_atomic_create_symlink(struct razor_atomic *atomic, const char *target,
1.112 + const char *path);
1.113 +/**
1.114 + * razor_atomic_create_file
1.115 + *
1.116 + * Create a file, replacing any existing object at this path except
1.117 + * a non-empty directory.
1.118 + *
1.119 + * Returns: A handle to be passed to razor_atomic_write() and
1.120 + * razor_atomic_close() or a negative value on error.
1.121 + */
1.122 +int razor_atomic_create_file(struct razor_atomic *atomic, const char *filename,
1.123 + mode_t mode);
1.124 +int razor_atomic_write(struct razor_atomic *atomic, int handle,
1.125 + const void *data, size_t size);
1.126 +int razor_atomic_close(struct razor_atomic *atomic, int handle);
1.127 +int razor_atomic_sync(struct razor_atomic *atomic, int handle);
1.128 +void razor_atomic_abort(struct razor_atomic *atomic, const char *error_msg);
1.129 +int razor_atomic_in_error_state(struct razor_atomic *atomic);
1.130 +
1.131 +/**
1.132 * SECTION:set
1.133 * @title: Package Set
1.134 * @short_description: Represents a set of packages and their metadata.
1.135 @@ -85,6 +187,9 @@
1.136 struct razor_package;
1.137 struct razor_property;
1.138
1.139 +#define RAZOR_HEADER_VERSION 2 /* Current version */
1.140 +#define RAZOR_HEADER_VERSION_MIN 1 /* Minimum version we support */
1.141 +
1.142 /**
1.143 * razor_set_create:
1.144 *
1.145 @@ -94,13 +199,20 @@
1.146 **/
1.147 struct razor_set *razor_set_create_without_root(void);
1.148 struct razor_set *razor_set_create(void);
1.149 -struct razor_set *razor_set_open(const char *filename);
1.150 -void razor_set_destroy(struct razor_set *set);
1.151 -int razor_set_write_to_fd(struct razor_set *set,
1.152 - int fd, uint32_t section_mask);
1.153 -int razor_set_write(struct razor_set *set,
1.154 +struct razor_set *razor_set_open(const char *filename,
1.155 + struct razor_atomic *atomic);
1.156 +uint32_t razor_set_get_header_version(struct razor_set *set);
1.157 +int razor_set_set_header_version(struct razor_set *set,
1.158 + uint32_t header_version);
1.159 +void razor_set_unref(struct razor_set *set);
1.160 +struct razor_set *razor_set_ref(struct razor_set *set);
1.161 +void razor_set_write_to_handle(struct razor_set *set,
1.162 + struct razor_atomic *atomic, int handle,
1.163 + uint32_t section_mask);
1.164 +int razor_set_write(struct razor_set *set, struct razor_atomic *atomic,
1.165 const char *filename, uint32_t setions);
1.166 -int razor_set_bind_sections(struct razor_set *set, const char *filename);
1.167 +int razor_set_bind_sections(struct razor_set *set, struct razor_atomic *atomic,
1.168 + const char *filename);
1.169
1.170 struct razor_package *
1.171 razor_set_get_package(struct razor_set *set, const char *package);
1.172 @@ -110,8 +222,9 @@
1.173 struct razor_package *package, ...);
1.174 int
1.175 razor_package_remove(struct razor_set *prev, struct razor_set *next,
1.176 - struct razor_package *package, const char *root,
1.177 - int install_count);
1.178 + struct razor_atomic *atomic, struct razor_package *package,
1.179 + const char *root, int install_count,
1.180 + enum razor_stage_type stage);
1.181
1.182 /**
1.183 * SECTION:iterator
1.184 @@ -230,6 +343,7 @@
1.185 enum razor_install_action *action,
1.186 int *count);
1.187
1.188 +void razor_install_iterator_rewind(struct razor_install_iterator *ii);
1.189 void razor_install_iterator_destroy(struct razor_install_iterator *ii);
1.190
1.191 /**
1.192 @@ -286,12 +400,14 @@
1.193 const char *path);
1.194 void razor_relocations_destroy(struct razor_relocations *relocations);
1.195
1.196 -struct razor_rpm *razor_rpm_open(const char *filename);
1.197 +struct razor_rpm *razor_rpm_open(const char *filename,
1.198 + struct razor_atomic *atomic);
1.199 void razor_rpm_get_details(struct razor_rpm *rpm, ...);
1.200 void razor_rpm_set_relocations(struct razor_rpm *rpm,
1.201 struct razor_relocations *relocations);
1.202 -int razor_rpm_install(struct razor_rpm *rpm, const char *root,
1.203 - int install_count);
1.204 +int razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic,
1.205 + const char *root, int install_count,
1.206 + enum razor_stage_type stage);
1.207 int razor_rpm_close(struct razor_rpm *rpm);
1.208
1.209 /**
1.210 @@ -378,14 +494,15 @@
1.211 struct razor_root;
1.212
1.213 int razor_root_create(const char *root);
1.214 -struct razor_root *razor_root_open(const char *root);
1.215 -struct razor_set *razor_root_open_read_only(const char *root);
1.216 +struct razor_root *
1.217 +razor_root_open(const char *root, struct razor_atomic *atomic);
1.218 +struct razor_set *razor_root_open_read_only(const char *root,
1.219 + struct razor_atomic *atomic);
1.220 struct razor_set *razor_root_get_system_set(struct razor_root *root);
1.221 int razor_root_close(struct razor_root *root);
1.222 void razor_root_update(struct razor_root *root, struct razor_set *next);
1.223 int razor_root_commit(struct razor_root *root);
1.224
1.225 -
1.226 /**
1.227 * SECTION:misc
1.228 * @title: Miscellaneous Functions
1.229 @@ -408,5 +525,8 @@
1.230 void razor_set_lua_loader(const char *modname, void (*loader)());
1.231 void (*razor_get_lua_loader(const char *modname))();
1.232
1.233 +char *razor_concat(const char *s, ...) RAZOR_MALLOC RAZOR_NULL_TERMINATED;
1.234 +
1.235 +const char *razor_system_arch(void);
1.236
1.237 #endif /* _RAZOR_H_ */