From 55cb92665bc7c79c81d141f3061e59bb9252b431 Mon Sep 17 00:00:00 2001 From: J. Ali Harlow Date: Thu, 16 Feb 2012 17:33:47 +0000 Subject: [PATCH] Allow multiple atomic transactions to be used with one root object. This allows transactions that include barriers to be performed while holding an exclusive system lock. --- configure.ac | 2 +- librazor/Makefile.am | 2 +- librazor/atomic-ktm.c | 52 +++++----- librazor/error.c | 36 ++++--- librazor/razor-internal.h | 23 +++-- librazor/razor.c | 40 +++----- librazor/razor.h | 38 ++++++-- librazor/root.c | 86 ++++++----------- librazor/rpm.c | 12 +- librazor/test-lua.c | 13 ++- librazor/util.c | 68 ++++++++----- src/main.c | 246 +++++++++++++++++++++++---------------------- src/rpm.c | 61 ++++------- 13 files changed, 343 insertions(+), 336 deletions(-) diff --git a/configure.ac b/configure.ac index 892f35f..98ebf5f 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ AM_MAINTAINER_MODE # LT_CURRENT=4 LT_REVISION=0 -LT_AGE=2 +LT_AGE=0 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) AC_SUBST(LT_AGE) diff --git a/librazor/Makefile.am b/librazor/Makefile.am index a63336d..28c0d26 100644 --- a/librazor/Makefile.am +++ b/librazor/Makefile.am @@ -52,7 +52,7 @@ librazor_la_LDFLAGS = -no-undefined \ if HAVE_LUA test_lua_SOURCES = test-lua.c - test_lua_LDADD = lua.lo util.lo types/libtypes.la $(LUA_LIBS) \ + test_lua_LDADD = lua.lo util.lo error.lo types/libtypes.la $(LUA_LIBS) \ ../gl/libgnu.la $(INTLLIBS) $(EXTRA_LIBS) TESTS = test-lua diff --git a/librazor/atomic-ktm.c b/librazor/atomic-ktm.c index 37b506e..3bf6dc6 100644 --- a/librazor/atomic-ktm.c +++ b/librazor/atomic-ktm.c @@ -142,7 +142,7 @@ razor_atomic_commit(struct razor_atomic *atomic) retval = !CommitTransaction(atomic->transaction); if (retval) { - atomic->error = razor_error_new_mswin(NULL, GetLastError()); + razor_set_error_mswin(&atomic->error, NULL, GetLastError()); RollbackTransaction(atomic->transaction); } @@ -210,15 +210,15 @@ razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root, if (err == ERROR_FILE_NOT_FOUND) { creating = 1; } else { - atomic->error = razor_error_new_mswin(buffer->str, - err); + razor_set_error_mswin(&atomic->error, + buffer->str, err); razor_wstr_destroy(buffer); return -1; } } else if (!(fa.dwFileAttributes& FILE_ATTRIBUTE_DIRECTORY)) { - atomic->error = razor_error_new_str(buffer->str, - "Not a directory"); + razor_set_error2(&atomic->error, buffer->str, + "Not a directory"); razor_wstr_destroy(buffer); return -1; } @@ -226,8 +226,9 @@ razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root, if (creating) { if (!CreateDirectoryTransactedW(NULL, buffer->str, NULL, atomic->transaction)) { - atomic->error = razor_error_new_mswin(buffer->str, - GetLastError()); + razor_set_error_mswin(&atomic->error, + buffer->str, + GetLastError()); razor_wstr_destroy(buffer); return -1; } @@ -287,7 +288,7 @@ razor_atomic_remove(struct razor_atomic *atomic, const char *path) * same path, this is likely to cause more problems than it solves. */ - atomic->error = razor_error_new_mswin(buf, err); + razor_set_error_mswin(&atomic->error, buf, err); free(buf); return -1; } @@ -315,7 +316,7 @@ razor_atomic_rename_file(struct razor_atomic *atomic, const char *oldpath, if (!MoveFileTransactedW(oldbuf, newbuf, NULL, NULL, flags, atomic->transaction)) - atomic->error = razor_error_new_mswin(newbuf, GetLastError()); + razor_set_error_mswin(&atomic->error, newbuf, GetLastError()); free(newbuf); free(oldbuf); @@ -340,7 +341,7 @@ razor_atomic_create_dir(struct razor_atomic *atomic, const char *dirname, err = GetLastError(); if (err != ERROR_FILE_EXISTS && err != ERROR_ALREADY_EXISTS) { abort: - atomic->error = razor_error_new_mswin(buf, err); + razor_set_error_mswin(&atomic->error, buf, err); free(buf); return -1; } @@ -380,9 +381,8 @@ razor_atomic_create_symlink(struct razor_atomic *atomic, const char *target, * and we don't always know that at the time when the * link is created, so it's a convienent lie for now. */ - atomic->error = razor_error_new_str(NULL, - "Symbolic links not supported " - "on this platform"); + razor_set_error(&atomic->error, NULL, + "Symbolic links not supported on this platform"); return -1; } @@ -401,7 +401,7 @@ razor_atomic_create_file(struct razor_atomic *atomic, const char *filename, files = realloc(atomic->files, (atomic->n_files+1) * sizeof(struct razor_atomic_file)); if (!files) { - atomic->error = razor_error_new_str(NULL, "Not enough memory"); + razor_set_error(&atomic->error, NULL, "Not enough memory"); return -1; } atomic->n_files++; @@ -428,8 +428,8 @@ razor_atomic_create_file(struct razor_atomic *atomic, const char *filename, NULL); if (files[i].h == INVALID_HANDLE_VALUE) { - atomic->error = razor_error_new_mswin(files[i].path, - GetLastError()); + razor_set_error_mswin(&atomic->error, files[i].path, + GetLastError()); free(files[i].path); atomic->n_files--; return -1; @@ -453,8 +453,9 @@ razor_atomic_write(struct razor_atomic *atomic, int handle, const void *data, while(size) { if (!WriteFile(atomic->files[handle].h, data, size, &written, NULL)) { - atomic->error = razor_error_new_mswin(atomic->files[handle].path, - GetLastError()); + razor_set_error_mswin(&atomic->error, + atomic->files[handle].path, + GetLastError()); (void)CloseHandle(atomic->files[handle].h); free(atomic->files[handle].path); @@ -483,8 +484,9 @@ razor_atomic_sync(struct razor_atomic *atomic, int handle) assert(atomic->files[handle].h != INVALID_HANDLE_VALUE); if (!CloseHandle(atomic->files[handle].h)) { - atomic->error = razor_error_new_mswin(atomic->files[handle].path, - GetLastError()); + razor_set_error_mswin(&atomic->error, + atomic->files[handle].path, + GetLastError()); free(atomic->files[handle].path); atomic->files[handle].path = NULL; atomic->files[handle].h = INVALID_HANDLE_VALUE; @@ -497,8 +499,9 @@ razor_atomic_sync(struct razor_atomic *atomic, int handle) atomic->files[handle].h = h; if (atomic->files[handle].h == INVALID_HANDLE_VALUE) { - atomic->error = razor_error_new_mswin(atomic->files[handle].path, - GetLastError()); + razor_set_error_mswin(&atomic->error, + atomic->files[handle].path, + GetLastError()); free(atomic->files[handle].path); atomic->files[handle].path = NULL; return -1; @@ -517,8 +520,9 @@ razor_atomic_close(struct razor_atomic *atomic, int handle) assert(atomic->files[handle].h != INVALID_HANDLE_VALUE); if (!CloseHandle(atomic->files[handle].h)) - atomic->error = razor_error_new_mswin(atomic->files[handle].path, - GetLastError()); + razor_set_error_mswin(&atomic->error, + atomic->files[handle].path, + GetLastError()); free(atomic->files[handle].path); atomic->files[handle].path = NULL; diff --git a/librazor/error.c b/librazor/error.c index 3670ff5..c46241c 100644 --- a/librazor/error.c +++ b/librazor/error.c @@ -62,37 +62,43 @@ razor_error_new_mswin(const wchar_t *path, DWORD err) return error; } -#endif -#if HAVE_WINDOWS_KTM -struct razor_error * -razor_error_new_str(const wchar_t *path, const char *str) -#else struct razor_error * -razor_error_new_str(const char *path, const char *str) -#endif +razor_error_new_str2(const wchar_t *path, const char *str) { struct razor_error *error; error = zalloc(sizeof *error); -#if HAVE_WINDOWS_KTM if (path) error->path = razor_utf16_to_utf8(path, -1); -#else + + error->str = strdup(str); + + return error; +} +#endif /* MSWIN_API */ + +RAZOR_EXPORT struct razor_error * +razor_error_new_str(const char *path, const char *str) +{ + struct razor_error *error; + + error = zalloc(sizeof *error); + if (path) error->path = strdup(path); -#endif error->str = strdup(str); return error; } -void razor_error_free(struct razor_error *error) +RAZOR_EXPORT void +razor_error_free(struct razor_error *error) { - free(error->path); - free(error->str); - free(error->msg); - free(error); + free(error->path); + free(error->str); + free(error->msg); + free(error); } diff --git a/librazor/razor-internal.h b/librazor/razor-internal.h index 691ef88..bf2517f 100644 --- a/librazor/razor-internal.h +++ b/librazor/razor-internal.h @@ -123,6 +123,7 @@ struct razor_set { struct array details_string_pool; struct razor_mapped_file *mapped_files; int lock_fd, ref_count; + enum razor_set_flags flags; }; struct import_entry { @@ -214,7 +215,9 @@ int razor_create_dir(const char *root, const char *path); int razor_remove(const char *path); int razor_write(int fd, const void *data, size_t size); -void *razor_file_get_contents(const char *filename, size_t *length); +void * +razor_file_get_contents(const char *filename, size_t *length, int private, + struct razor_error **error); int razor_file_free_contents(void *addr, size_t length); @@ -251,13 +254,17 @@ struct razor_error { #ifdef MSWIN_API struct razor_error *razor_error_new_mswin(const wchar_t *path, DWORD error); -#endif - -#if HAVE_WINDOWS_KTM -struct razor_error *razor_error_new_str(const wchar_t *path, const char *str); -#else -struct razor_error *razor_error_new_str(const char *path, const char *str); -#endif +struct razor_error *razor_error_new_str2(const wchar_t *path, const char *str); + +#define razor_set_error_mswin(error, path, err) \ + if (error) \ + *(error) = razor_error_new_mswin(path, err); \ + else +#define razor_set_error2(error, path, str) \ + if (error) \ + *(error) = razor_error_new_str2(path, str); \ + else +#endif /* MSWIN_API */ /* Atomic functions */ diff --git a/librazor/razor.c b/librazor/razor.c index c79697f..6685192 100644 --- a/librazor/razor.c +++ b/librazor/razor.c @@ -48,17 +48,6 @@ #define O_BINARY 0 #endif -void * -zalloc(size_t size) -{ - void *p; - - p = malloc(size); - memset(p, 0, size); - - return p; -} - struct razor_set_section_index { const char *name; uint32_t offset; @@ -102,6 +91,8 @@ razor_set_create_without_root(void) set->ref_count = 1; set->header_version = RAZOR_HEADER_VERSION; + + set->flags = RAZOR_SET_PRIVATE; } return set; @@ -149,27 +140,25 @@ struct razor_mapped_file { }; RAZOR_EXPORT int -razor_set_bind_sections(struct razor_set *set, struct razor_atomic *atomic, - const char *filename) +razor_set_bind_sections(struct razor_set *set, const char *filename, + enum razor_set_flags flags, struct razor_error **error) { struct razor_set_section *s, *sections; struct razor_mapped_file *file; const char *pool, *reason; - char *msg; struct array *array; int i, j; file = zalloc(sizeof *file); if (file == NULL) { - razor_atomic_abort(atomic, "Not enough memory"); + razor_set_error(error, NULL, "Not enough memory"); return -1; } - file->header = razor_file_get_contents(filename, &file->size); + file->header = razor_file_get_contents(filename, &file->size, + flags & RAZOR_SET_PRIVATE, + error); if (!file->header) { - msg = razor_concat(filename, ": ", strerror(errno), NULL); - razor_atomic_abort(atomic, msg); - free(msg); free(file); return -1; } @@ -185,14 +174,14 @@ razor_set_bind_sections(struct razor_set *set, struct razor_atomic *atomic, reason = NULL; if (reason) { - msg = razor_concat(filename, ": ", reason, NULL); - razor_atomic_abort(atomic, msg); - free(msg); + razor_set_error(error, filename, reason); razor_file_free_contents(file->header, file->size); free(file); return -1; } + set->flags = flags & RAZOR_SET_PRIVATE; + set->header_version = file->header->version; if (set->mapped_files == NULL) { @@ -226,19 +215,20 @@ razor_set_bind_sections(struct razor_set *set, struct razor_atomic *atomic, } RAZOR_EXPORT struct razor_set * -razor_set_open(const char *filename, struct razor_atomic *atomic) +razor_set_open(const char *filename, enum razor_set_flags flags, + struct razor_error **error) { struct razor_set *set; set = zalloc(sizeof *set); if (!set) { - razor_atomic_abort(atomic, "Not enough memory"); + razor_set_error(error, NULL, "Not enough memory"); return NULL; } set->lock_fd = -1; set->ref_count = 1; - if (razor_set_bind_sections(set, atomic, filename)) { + if (razor_set_bind_sections(set, filename, flags, error)) { free(set); return NULL; } diff --git a/librazor/razor.h b/librazor/razor.h index 6ee7323..4988764 100644 --- a/librazor/razor.h +++ b/librazor/razor.h @@ -95,6 +95,16 @@ enum razor_property_flags { RAZOR_PROPERTY_POSTUN }; +enum razor_set_flags { + /* + * Create a private copy of the razor set such that changes made + * to the underlying file are not visible in the razor set. + * If this flag is not set then the caller must ensure that the + * underlying file (if any) is not changed. + */ + RAZOR_SET_PRIVATE = 1 << 0, +}; + /** * SECTION:error * @title: Error reporting @@ -104,6 +114,13 @@ enum razor_property_flags { */ struct razor_error; +struct razor_error *razor_error_new_str(const char *path, const char *str); + +#define razor_set_error(error, path, str) \ + if (error) \ + *(error) = razor_error_new_str(path, str); \ + else + const char *razor_error_get_msg(struct razor_error *error); void razor_error_free(struct razor_error *error); @@ -216,8 +233,9 @@ struct razor_property; **/ struct razor_set *razor_set_create_without_root(void); struct razor_set *razor_set_create(void); -struct razor_set *razor_set_open(const char *filename, - struct razor_atomic *atomic); +struct razor_set * +razor_set_open(const char *filename, enum razor_set_flags flags, + struct razor_error **error); uint32_t razor_set_get_header_version(struct razor_set *set); int razor_set_set_header_version(struct razor_set *set, uint32_t header_version); @@ -228,8 +246,9 @@ void razor_set_write_to_handle(struct razor_set *set, uint32_t section_mask); int razor_set_write(struct razor_set *set, struct razor_atomic *atomic, const char *filename, uint32_t setions); -int razor_set_bind_sections(struct razor_set *set, struct razor_atomic *atomic, - const char *filename); +int +razor_set_bind_sections(struct razor_set *set, const char *filename, + enum razor_set_flags flags, struct razor_error **error); struct razor_package * razor_set_get_package(struct razor_set *set, const char *package); @@ -528,13 +547,14 @@ struct razor_root; int razor_root_create(const char *root); struct razor_root * -razor_root_open(const char *root, struct razor_atomic *atomic); -struct razor_set *razor_root_open_read_only(const char *root, - struct razor_atomic *atomic); +razor_root_open(const char *root, struct razor_error **error); +struct razor_set * +razor_root_open_read_only(const char *root, struct razor_error **error); struct razor_set *razor_root_get_system_set(struct razor_root *root); int razor_root_close(struct razor_root *root); -void razor_root_update(struct razor_root *root, struct razor_set *next); -int razor_root_commit(struct razor_root *root); +int +razor_root_update(struct razor_root *root, struct razor_set *next, + struct razor_atomic *atomic); /** * SECTION:misc diff --git a/librazor/root.c b/librazor/root.c index 81568b4..180434d 100644 --- a/librazor/root.c +++ b/librazor/root.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc - * Copyright (C) 2009, 2011 J. Ali Harlow + * Copyright (C) 2009, 2011, 2012 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,7 +49,6 @@ static const char system_repo_filename[] = "system.rzdb"; * will see the system as permenantly locked. */ static const char system_lock_filename[] = "system-next.rzdb"; -static const char system_tmp_filename[] = "system.tmp"; #ifdef MSWIN_API #define RAZOR_ROOT_PATH NULL #else @@ -59,10 +58,7 @@ static const char *razor_root_path = RAZOR_ROOT_PATH; struct razor_root { struct razor_set *system; - struct razor_set *next; - struct razor_atomic *atomic; - int handle; - char *path, *new_path; + char *path; }; static void @@ -136,7 +132,7 @@ razor_root_create(const char *root) } RAZOR_EXPORT struct razor_root * -razor_root_open(const char *root, struct razor_atomic *atomic) +razor_root_open(const char *root, struct razor_error **error) { struct razor_root *image; char *lock_path; @@ -147,16 +143,14 @@ razor_root_open(const char *root, struct razor_atomic *atomic) razor_root_init(); image = malloc(sizeof *image); if (image == NULL) { - razor_atomic_abort(atomic, "Not enough memory"); + razor_set_error(error, NULL, "Not enough memory"); return NULL; } - image->atomic = atomic; - image->system = razor_set_create_without_root(); if (image->system == NULL) { free(image); - razor_atomic_abort(atomic, "Not enough memory"); + razor_set_error(error, NULL, "Not enough memory"); return NULL; } @@ -168,19 +162,8 @@ razor_root_open(const char *root, struct razor_atomic *atomic) free(lock_path); if (r < 0) { - razor_atomic_abort(atomic, - "Failed to aquire exclusive system lock"); - razor_set_unref(image->system); - free(image); - return NULL; - } - - image->new_path = razor_concat(root, razor_root_path, "/", - system_tmp_filename, NULL); - image->handle = razor_atomic_create_file(atomic, image->new_path, - S_IRWXU | S_IRWXG | S_IRWXO); - if (image->handle < 0) { - free(image->new_path); + razor_set_error(error, NULL, + "Failed to aquire exclusive system lock"); razor_set_unref(image->system); free(image); return NULL; @@ -189,9 +172,8 @@ razor_root_open(const char *root, struct razor_atomic *atomic) image->path = razor_concat(root, razor_root_path, "/", system_repo_filename, NULL); - if (razor_set_bind_sections(image->system, atomic, image->path)) { - unlink(image->new_path); - free(image->new_path); + if (razor_set_bind_sections(image->system, image->path, + RAZOR_SET_PRIVATE, error)) { free(image->path); razor_set_unref(image->system); free(image); @@ -202,7 +184,7 @@ razor_root_open(const char *root, struct razor_atomic *atomic) } RAZOR_EXPORT struct razor_set * -razor_root_open_read_only(const char *root, struct razor_atomic *atomic) +razor_root_open_read_only(const char *root, struct razor_error **error) { char *path; struct razor_set *set; @@ -212,15 +194,15 @@ razor_root_open_read_only(const char *root, struct razor_atomic *atomic) razor_root_init(); set = razor_set_create_without_root(); if (set == NULL) { - razor_atomic_abort(atomic, "Not enough memory"); + razor_set_error(error, NULL, "Not enough memory"); return NULL; } path = razor_concat(root, razor_root_path, "/", system_lock_filename, NULL); if (razor_set_aquire_lock(set, path, 0) < 0) { - razor_atomic_abort(atomic, "Failed to aquire non-exclusive " - "system lock"); + razor_set_error(error, NULL, + "Failed to aquire non-exclusive system lock"); free(path); razor_set_unref(set); return NULL; @@ -230,7 +212,7 @@ razor_root_open_read_only(const char *root, struct razor_atomic *atomic) path = razor_concat(root, razor_root_path, "/", system_repo_filename, NULL); - if (razor_set_bind_sections(set, atomic, path)) { + if (razor_set_bind_sections(set, path, 0, error)) { razor_set_unref(set); set = NULL; } @@ -254,44 +236,34 @@ razor_root_close(struct razor_root *root) assert (root != NULL); razor_set_unref(root->system); - razor_atomic_close(root->atomic, root->handle); - razor_atomic_remove(root->atomic, root->new_path); free(root->path); - free(root->new_path); free(root); return 0; } -RAZOR_EXPORT void -razor_root_update(struct razor_root *root, struct razor_set *next) +RAZOR_EXPORT int +razor_root_update(struct razor_root *root, struct razor_set *next, + struct razor_atomic *atomic) { + int handle, retval; + assert (root != NULL); assert (next != NULL); - razor_root_init(); - razor_set_write_to_handle(next, root->atomic, root->handle, - RAZOR_SECTION_ALL); - root->next = next; + handle = razor_atomic_create_file(atomic, root->path, + S_IRWXU | S_IRWXG | S_IRWXO); + if (handle < 0) + return handle; - /* Sync the new repo file so the new package set is on disk - * before we start upgrading. */ - razor_atomic_sync(root->atomic, root->handle); -} + razor_set_write_to_handle(next, atomic, handle, RAZOR_SECTION_ALL); -RAZOR_EXPORT int -razor_root_commit(struct razor_root *root) -{ - int retval; - assert (root != NULL); + retval = razor_atomic_close(atomic, handle); - razor_atomic_close(root->atomic, root->handle); - retval = razor_atomic_rename_file(root->atomic, root->new_path, - root->path); - razor_set_unref(root->system); - free(root->path); - free(root->new_path); - free(root); + if (!retval) { + razor_set_unref(root->system); + root->system = razor_set_ref(next); + } return retval; } diff --git a/librazor/rpm.c b/librazor/rpm.c index 57aeda2..a6434f1 100644 --- a/librazor/rpm.c +++ b/librazor/rpm.c @@ -606,6 +606,7 @@ razor_rpm_open(const char *filename, struct razor_atomic *atomic) { struct razor_rpm *rpm; struct rpm_header_index *base, *index; + struct razor_error *error = NULL; unsigned int count, i, nindex, hsize; const char *name, *prefix; char *s; @@ -619,11 +620,10 @@ razor_rpm_open(const char *filename, struct razor_atomic *atomic) } memset(rpm, 0, sizeof *rpm); - rpm->map = razor_file_get_contents(filename, &rpm->size); + rpm->map = razor_file_get_contents(filename, &rpm->size, 0, &error); if (!rpm->map) { - s = razor_concat(filename, ": ", strerror(errno), NULL); - razor_atomic_abort(atomic, s); - free(s); + razor_atomic_abort(atomic, razor_error_get_msg(error)); + razor_error_free(error); free(rpm); return NULL; } @@ -1138,7 +1138,7 @@ razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic, struct cpio_file_header *header; struct stat buf; unsigned int mode; - const char *path, *name; + const char *path; size_t filesize; char *s; int retval = 0; @@ -1153,7 +1153,7 @@ razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic, /* FIXME: Only do this before a transaction, not per rpm. */ if (*root && (stat(root, &buf) < 0 || !S_ISDIR(buf.st_mode))) { s = razor_concat(root, ": Directory does not exist", NULL); - razor_atomic_abort(stderr, s); + razor_atomic_abort(atomic, s); free(s); return -1; } diff --git a/librazor/test-lua.c b/librazor/test-lua.c index ec75071..fc194b4 100644 --- a/librazor/test-lua.c +++ b/librazor/test-lua.c @@ -65,6 +65,7 @@ int main(int argc, char *argv[]) size_t len; char *s, *test_file, *srcdir; FILE *fp; + struct razor_error *error = NULL; if (argc > 2) { fprintf(stderr, "usage: %s [TESTS-FILE]\n", argv[0]); @@ -94,22 +95,26 @@ int main(int argc, char *argv[]) fclose(fp); free(s); - script = razor_file_get_contents(test_file, &len); + script = razor_file_get_contents(test_file, &len, 0, &error); if (!script) { srcdir = getenv("srcdir"); if (srcdir && errno == ENOENT && *test_file != '/') { + razor_error_free(error); s = malloc(strlen(srcdir) + strlen(test_file) + 2); strcpy(s, srcdir); strcat(s, "/"); strcat(s, test_file); - script = razor_file_get_contents(s, &len); + script = razor_file_get_contents(s, &len, 0, &error); if (!script) { - perror(s); + fprintf(stderr, "%s\n", + razor_error_get_msg(error)); + razor_error_free(error); exit(1); } free(s); } else { - perror(test_file); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); exit(1); } } diff --git a/librazor/util.c b/librazor/util.c index 047a5d6..5ede1a1 100644 --- a/librazor/util.c +++ b/librazor/util.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc - * Copyright (C) 2009, 2011 J. Ali Harlow + * Copyright (C) 2009, 2011, 2012 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,54 +52,70 @@ char *program_name = "librazor"; void * -razor_file_get_contents(const char *filename, size_t *length) +zalloc(size_t size) +{ + void *p; + + p = malloc(size); + memset(p, 0, size); + + return p; +} + +void * +razor_file_get_contents(const char *filename, size_t *length, int private, + struct razor_error **error) { int fd; struct stat st; - void *addr; -#if !HAVE_SYS_MMAN_H + void *addr = NULL; size_t nb; ssize_t res; -#endif fd = open(filename, O_RDONLY | O_BINARY); - if (fd < 0) + if (fd < 0) { + razor_set_error(error, filename, strerror(errno)); return NULL; + } if (fstat(fd, &st) < 0) { + razor_set_error(error, filename, strerror(errno)); close(fd); return NULL; } *length = st.st_size; #if HAVE_SYS_MMAN_H - addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); -#else - addr = malloc(st.st_size); - if (addr) { - nb = 0; - while(nb < st.st_size) { - res = read(fd, addr + nb, st.st_size - nb); - if (res <= 0) { - free(addr); - addr = NULL; - break; - } - nb += res; - } + if (!private) { + addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (addr == MAP_FAILED) + addr = NULL; } #endif + if (!addr) { + addr = malloc(st.st_size); + if (addr) { + nb = 0; + while(nb < st.st_size) { + res = read(fd, addr + nb, st.st_size - nb); + if (res <= 0) { + razor_set_error(error, filename, + strerror(errno)); + free(addr); + addr = NULL; + break; + } + nb += res; + } + } else + razor_set_error(error, NULL, "Not enough memory"); + } close(fd); -#if HAVE_SYS_MMAN_H - if (addr == MAP_FAILED) - addr = NULL; -#endif - return addr; } -razor_file_free_contents(void *addr, size_t length) +int razor_file_free_contents(void *addr, size_t length) { #if HAVE_SYS_MMAN_H return munmap(addr, length); diff --git a/src/main.c b/src/main.c index 032238c..0bc59ee 100644 --- a/src/main.c +++ b/src/main.c @@ -55,9 +55,9 @@ update_packages(struct razor_transaction *trans, struct razor_relocations *relocations, enum razor_stage_type stage); static int -update_system(const char *install_root, struct razor_relocations *relocations, - struct razor_transaction *trans, struct razor_set *system, - struct razor_set *next, const char *verb); +update_system(struct razor_root *root, struct razor_relocations *relocations, + struct razor_transaction *trans, struct razor_set *next, + const char *verb); static struct razor_package_iterator * create_iterator_from_argv(struct razor_set *set, int argc, const char *argv[]) @@ -120,7 +120,7 @@ static int command_list(int argc, const char *argv[]) { struct razor_package_iterator *pi; - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; uint32_t flags = 0; int i = 0; @@ -130,11 +130,10 @@ command_list(int argc, const char *argv[]) i++; } - atomic = razor_atomic_open("List installed packages"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -142,7 +141,6 @@ command_list(int argc, const char *argv[]) list_packages(pi, flags); razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -188,16 +186,15 @@ static int list_properties(int argc, const char *argv[], uint32_t type) { struct razor_set *set; - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_package *package; struct razor_package_iterator *pi; const char *name, *version, *arch; - atomic = razor_atomic_open("List package properties"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -210,7 +207,6 @@ list_properties(int argc, const char *argv[], uint32_t type) list_package_properties(set, package, type); razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -243,16 +239,15 @@ static int command_list_scripts(int argc, const char *argv[]) { struct razor_set *set; - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_package *package; struct razor_package_iterator *pi; const char *preunprog, *preun, *postunprog, *postun; - atomic = razor_atomic_open("List package scripts"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -278,7 +273,6 @@ command_list_scripts(int argc, const char *argv[]) } razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -286,20 +280,18 @@ command_list_scripts(int argc, const char *argv[]) static int command_list_files(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; - atomic = razor_atomic_open("List package files"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } razor_set_list_files(set, argv[0]); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -307,15 +299,14 @@ command_list_files(int argc, const char *argv[]) static int command_list_file_packages(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_package_iterator *pi; - atomic = razor_atomic_open("List file packages"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -324,7 +315,6 @@ command_list_file_packages(int argc, const char *argv[]) razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -332,17 +322,16 @@ command_list_file_packages(int argc, const char *argv[]) static int command_list_package_files(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_package_iterator *pi; struct razor_package *package; const char *name, *version, *arch; - atomic = razor_atomic_open("List package files"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -356,7 +345,6 @@ command_list_package_files(int argc, const char *argv[]) razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -366,7 +354,7 @@ list_property_packages(const char *ref_name, const char *ref_version, uint32_t type) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_property *property; struct razor_property_iterator *prop_iter; @@ -377,11 +365,10 @@ list_property_packages(const char *ref_name, if (ref_name == NULL) return 0; - atomic = razor_atomic_open("List package properties"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -406,7 +393,6 @@ list_property_packages(const char *ref_name, razor_property_iterator_destroy(prop_iter); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -540,15 +526,14 @@ command_import_rpmdb(int argc, const char *argv[]) { struct razor_set *set; struct razor_root *root; + struct razor_error *error = NULL; struct razor_atomic *atomic; int retval; - atomic = razor_atomic_open("Import RPM database"); - - root = razor_root_open(install_root, atomic); + root = razor_root_open(install_root, &error); if (root == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -556,14 +541,17 @@ command_import_rpmdb(int argc, const char *argv[]) if (set == NULL) return 1; - razor_root_update(root, set); + atomic = razor_atomic_open("Import RPM database"); + + retval = razor_root_update(root, set, atomic); - retval = razor_root_commit(root); if (retval) fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); razor_atomic_destroy(atomic); + razor_root_close(root); + return retval; } #endif @@ -619,20 +607,18 @@ command_remove(int argc, const char *argv[]) { struct razor_set *system, *upstream, *next; struct razor_transaction *trans; - struct razor_atomic *atomic; + struct razor_error *error = NULL; + struct razor_root *root; int i, retval; - atomic = razor_atomic_open("Remove packages"); - - system = razor_root_open_read_only(install_root, atomic); - if (system == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + root = razor_root_open(install_root, &error); + if (root == NULL) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } - razor_atomic_destroy(atomic); - + system = razor_root_get_system_set(root); upstream = razor_set_create_without_root(); trans = razor_transaction_create(system, upstream); razor_set_unref(upstream); @@ -640,7 +626,7 @@ command_remove(int argc, const char *argv[]) if (mark_packages_for_removal(trans, system, argv[i]) == 0) { fprintf(stderr, "no match for %s\n", argv[i]); razor_transaction_destroy(trans); - razor_set_unref(system); + razor_root_close(root); return 1; } } @@ -649,17 +635,16 @@ command_remove(int argc, const char *argv[]) retval = razor_transaction_describe(trans); if (retval) { razor_transaction_destroy(trans); - razor_set_unref(system); + razor_root_close(root); return 1; } next = razor_transaction_commit(trans); - retval = update_system(install_root, NULL, trans, system, next, - "Remove"); + retval = update_system(root, NULL, trans, next, "Remove"); razor_transaction_destroy(trans); - razor_set_unref(system); + razor_root_close(root); razor_set_unref(next); return retval; @@ -682,15 +667,19 @@ print_diff(enum razor_diff_action action, static int command_diff(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set, *updated; - atomic = razor_atomic_open("Show package differences"); - set = razor_root_open_read_only(install_root, atomic); - updated = razor_set_open(rawhide_repo_filename, atomic); - if (set == NULL || updated == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + set = razor_root_open_read_only(install_root, &error); + if (set) + updated = razor_set_open(rawhide_repo_filename, 0, &error); + else + updated = NULL; + if (updated == NULL) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); + if (set) + razor_set_unref(set); return 1; } @@ -698,7 +687,6 @@ command_diff(int argc, const char *argv[]) razor_set_unref(set); razor_set_unref(updated); - razor_atomic_destroy(atomic); return 0; } @@ -997,12 +985,11 @@ update_packages(struct razor_transaction *trans, } static int -update_system(const char *install_root, struct razor_relocations *relocations, - struct razor_transaction *trans, struct razor_set *system, - struct razor_set *next, const char *verb) +update_system(struct razor_root *root, struct razor_relocations *relocations, + struct razor_transaction *trans, struct razor_set *next, + const char *verb) { - struct razor_root *root; - struct razor_set *set; + struct razor_set *system, *set; struct razor_atomic *atomic; struct razor_install_iterator *ii; int r, retval = 0; @@ -1011,6 +998,8 @@ update_system(const char *install_root, struct razor_relocations *relocations, description = razor_concat(verb, " packages", NULL); + system = razor_set_ref(razor_root_get_system_set(root)); + ii = razor_set_create_install_iterator(system, next); do { @@ -1018,20 +1007,10 @@ update_system(const char *install_root, struct razor_relocations *relocations, atomic = razor_atomic_open(description); - root = razor_root_open(install_root, atomic); - if (root == NULL) { - fprintf(stderr, "%s\n", - razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); - retval = 1; - break; - } - r = update_packages(trans, ii, system, next, atomic, relocations, RAZOR_STAGE_SCRIPTS_PRE); if (r < 0) { fprintf(stderr, "%s aborted\n", verb); - razor_root_close(root); retval = r; } else { razor_install_iterator_seek(ii, pos); @@ -1040,12 +1019,11 @@ update_system(const char *install_root, struct razor_relocations *relocations, if (r == 1) { set = razor_install_iterator_commit_set(ii); - razor_root_update(root, set); + razor_root_update(root, set, atomic); razor_set_unref(set); } else if (r == 0) - razor_root_update(root, next); + razor_root_update(root, next, atomic); - (void)razor_root_commit(root); retval = razor_atomic_commit(atomic); if (retval) fprintf(stderr, "%s\n", @@ -1061,6 +1039,8 @@ update_system(const char *install_root, struct razor_relocations *relocations, razor_atomic_destroy(atomic); } while(!retval && r == 1); + razor_set_unref(system); + free(description); return retval; @@ -1069,10 +1049,12 @@ update_system(const char *install_root, struct razor_relocations *relocations, static int command_install_or_update(int argc, const char *argv[], int do_update) { - struct razor_relocations *relocations=NULL; + struct razor_relocations *relocations = NULL; struct razor_set *system, *upstream, *next, *set; struct razor_transaction *trans; + struct razor_error *error = NULL; struct razor_atomic *atomic; + struct razor_root *root; int i, retval, len, dependencies = 1; char *oldpath; @@ -1104,18 +1086,18 @@ command_install_or_update(int argc, const char *argv[], int do_update) break; } + upstream = razor_set_open(rawhide_repo_filename, 0, &error); + if (upstream == NULL) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); + return 1; + } + if (do_update) atomic = razor_atomic_open("Update packages"); else atomic = razor_atomic_open("Install packages"); - upstream = razor_set_open(rawhide_repo_filename, atomic); - if (upstream == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); - return 1; - } - if (relocations) { set = relocate_packages(upstream, atomic, relocations); if (set == NULL) { @@ -1129,8 +1111,18 @@ command_install_or_update(int argc, const char *argv[], int do_update) upstream = set; } - system = razor_root_open_read_only(install_root, atomic); + root = razor_root_open(install_root, &error); + if (root == NULL) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); + razor_atomic_destroy(atomic); + razor_set_unref(upstream); + if (relocations) + razor_relocations_destroy(relocations); + return 1; + } + system = razor_root_get_system_set(root); trans = razor_transaction_create(system, upstream); if (i == argc && do_update) @@ -1142,9 +1134,11 @@ command_install_or_update(int argc, const char *argv[], int do_update) if (mark_packages_for_update(trans, upstream, argv[i]) == 0) { fprintf(stderr, "no package matched %s\n", argv[i]); razor_transaction_destroy(trans); + razor_root_close(root); razor_set_unref(upstream); - razor_set_unref(system); razor_atomic_destroy(atomic); + if (relocations) + razor_relocations_destroy(relocations); return 1; } } @@ -1154,8 +1148,10 @@ command_install_or_update(int argc, const char *argv[], int do_update) if (razor_transaction_describe(trans) > 0) { razor_transaction_destroy(trans); razor_set_unref(upstream); - razor_set_unref(system); + razor_root_close(root); razor_atomic_destroy(atomic); + if (relocations) + razor_relocations_destroy(relocations); return 1; } } @@ -1166,8 +1162,10 @@ command_install_or_update(int argc, const char *argv[], int do_update) fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); razor_transaction_destroy(trans); razor_set_unref(upstream); - razor_set_unref(system); + razor_root_close(root); razor_atomic_destroy(atomic); + if (relocations) + razor_relocations_destroy(relocations); return 1; } @@ -1179,22 +1177,24 @@ command_install_or_update(int argc, const char *argv[], int do_update) razor_set_unref(next); razor_transaction_destroy(trans); razor_set_unref(upstream); - razor_set_unref(system); + razor_root_close(root); razor_atomic_destroy(atomic); + if (relocations) + razor_relocations_destroy(relocations); return 1; } - retval = update_system(install_root, relocations, trans, system, next, + retval = update_system(root, relocations, trans, next, do_update ? "Update" : "Install"); razor_set_unref(upstream); + razor_root_close(root); razor_transaction_destroy(trans); if (relocations) razor_relocations_destroy(relocations); razor_set_unref(next); - razor_set_unref(system); return retval; } @@ -1220,6 +1220,7 @@ command_init(int argc, const char *argv[]) static int command_download(int argc, const char *argv[]) { + struct razor_error *error = NULL; struct razor_atomic *atomic; struct razor_set *set; struct razor_package_iterator *pi; @@ -1228,6 +1229,13 @@ command_download(int argc, const char *argv[]) char url[256], file[256]; int matches = 0; + set = razor_set_open(rawhide_repo_filename, 0, &error); + if (set == NULL) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); + return 1; + } + atomic = razor_atomic_open("Download packages"); if (razor_atomic_create_dir(atomic, "rpms", @@ -1237,8 +1245,6 @@ command_download(int argc, const char *argv[]) return 1; } - set = razor_set_open(rawhide_repo_filename, atomic); - if (razor_atomic_commit(atomic)) { fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); razor_atomic_destroy(atomic); @@ -1279,18 +1285,17 @@ command_download(int argc, const char *argv[]) static int command_info(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_package_iterator *pi; struct razor_package *package; const char *pattern = argv[0], *name, *version, *arch; const char *summary, *description, *url, *license; - atomic = razor_atomic_open("Package info"); - set = razor_root_open_read_only(install_root, atomic); + set = razor_root_open_read_only(install_root, &error); if (set == NULL) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } @@ -1322,7 +1327,6 @@ command_info(int argc, const char *argv[]) } razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); return 0; } @@ -1332,7 +1336,7 @@ command_info(int argc, const char *argv[]) static int command_search(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_package_iterator *pi; struct razor_package *package; @@ -1347,14 +1351,12 @@ command_search(int argc, const char *argv[]) snprintf(pattern, sizeof pattern, "*%s*", argv[0]); - atomic = razor_atomic_open("Search packages"); - set = razor_set_open(rawhide_repo_filename, atomic); - if (set == NULL || razor_atomic_commit(atomic)) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + set = razor_set_open(rawhide_repo_filename, 0, &error); + if (set == NULL) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return 1; } - razor_atomic_destroy(atomic); pi = razor_package_iterator_create(set); while (razor_package_iterator_next(pi, &package, diff --git a/src/rpm.c b/src/rpm.c index 623c41a..2277653 100644 --- a/src/rpm.c +++ b/src/rpm.c @@ -465,23 +465,21 @@ create_set_from_command_line(int argc, const char *argv[]) static void command_query(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_package_iterator *pi; struct razor_package *package; const char *name, *version, *arch; - atomic = razor_atomic_open("Query packages"); if (option_package) { set = create_set_from_command_line(argc, argv); argc = 0; option_all = 1; } else { - set = razor_root_open_read_only(option_root, atomic); + set = razor_root_open_read_only(option_root, &error); if (!set) { - fprintf(stderr, "%s\n", - razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return; } } @@ -521,29 +519,26 @@ command_query(int argc, const char *argv[]) razor_package_iterator_destroy(pi); razor_set_unref(set); - razor_atomic_destroy(atomic); } static void command_verify(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set; struct razor_package_iterator *pi; struct razor_package *package; const char *name, *version, *arch; - atomic = razor_atomic_open("Verify packages"); if (option_package) { set = create_set_from_command_line(argc, argv); argc = 0; option_all = 1; } else { - set = razor_root_open_read_only(option_root, atomic); + set = razor_root_open_read_only(option_root, &error); if (!set) { - fprintf(stderr, "%s\n", - razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); return; } } @@ -560,7 +555,6 @@ command_verify(int argc, const char *argv[]) } razor_package_iterator_destroy(pi); - razor_atomic_destroy(atomic); } static void @@ -580,7 +574,7 @@ update_package(enum razor_diff_action action, static void command_erase(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set, *upstream, *next; struct razor_transaction *trans; struct razor_package_query *query; @@ -592,15 +586,12 @@ command_erase(int argc, const char *argv[]) exit(1); } - atomic = razor_atomic_open("Erase packages"); - - set = razor_set_open(repo_filename, atomic); - if (!set || razor_atomic_commit(atomic)) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + set = razor_set_open(repo_filename, RAZOR_SET_PRIVATE, &error); + if (!set) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); exit(1); } - razor_atomic_destroy(atomic); upstream = razor_set_create(); trans = razor_transaction_create(set, upstream); @@ -639,7 +630,7 @@ command_erase(int argc, const char *argv[]) static void command_install(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set, *upstream, *next; struct razor_transaction *trans; struct razor_package_iterator *pi; @@ -650,14 +641,11 @@ command_install(int argc, const char *argv[]) exit(1); } - atomic = razor_atomic_open("Install packages"); - - set = razor_set_open(repo_filename, atomic); - if (!set || razor_atomic_commit(atomic)) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + set = razor_set_open(repo_filename, RAZOR_SET_PRIVATE, &error); + if (!set) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); } - razor_atomic_destroy(atomic); upstream = create_set_from_command_line(argc, argv); trans = razor_transaction_create(set, upstream); @@ -693,7 +681,7 @@ command_install(int argc, const char *argv[]) static void command_update(int argc, const char *argv[]) { - struct razor_atomic *atomic; + struct razor_error *error = NULL; struct razor_set *set, *upstream, *next; struct razor_transaction *trans; struct razor_package_iterator *pi; @@ -704,14 +692,11 @@ command_update(int argc, const char *argv[]) exit(1); } - atomic = razor_atomic_open("Update packages"); - - set = razor_set_open(repo_filename, atomic); - if (!set || razor_atomic_commit(atomic)) { - fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic)); - razor_atomic_destroy(atomic); + set = razor_set_open(repo_filename, RAZOR_SET_PRIVATE, &error); + if (!set) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); } - razor_atomic_destroy(atomic); upstream = create_set_from_command_line(argc, argv); trans = razor_transaction_create(set, upstream); -- 1.7.1