From 5dcae19aa4af7208b4d29c88cac3c70fe7e5e261 Mon Sep 17 00:00:00 2001 From: J. Ali Harlow Date: Thu, 16 Feb 2012 17:44:25 +0000 Subject: [PATCH] razor_create_root() should take an error pointer --- librazor/razor.h | 2 +- librazor/root.c | 19 ++++++++----------- src/main.c | 12 +++++++++++- src/rpm.c | 10 ++++++++-- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/librazor/razor.h b/librazor/razor.h index 4988764..c004fcb 100644 --- a/librazor/razor.h +++ b/librazor/razor.h @@ -545,7 +545,7 @@ struct razor_set *razor_set_create_from_rpmdb(void); **/ struct razor_root; -int razor_root_create(const char *root); +int razor_root_create(const char *root, struct razor_error **error); struct razor_root * razor_root_open(const char *root, struct razor_error **error); struct razor_set * diff --git a/librazor/root.c b/librazor/root.c index 180434d..f3992d3 100644 --- a/librazor/root.c +++ b/librazor/root.c @@ -77,7 +77,7 @@ razor_root_init(void) } RAZOR_EXPORT int -razor_root_create(const char *root) +razor_root_create(const char *root, struct razor_error **error) { int retval; struct stat buf; @@ -92,16 +92,12 @@ razor_root_create(const char *root) /* root is file system root */ } else if (stat(root, &buf) < 0) { if (mkdir(root, 0777) < 0) { - fprintf(stderr, - "could not create install root \"%s\"\n", - root); + razor_set_error(error, root, + "Could not create install root"); return -1; } - fprintf(stderr, "created install root \"%s\"\n", root); } else if (!S_ISDIR(buf.st_mode)) { - fprintf(stderr, - "install root \"%s\" exists, but is not a directory\n", - root); + razor_set_error(error, root, "Not a directory"); return -1; } @@ -109,8 +105,8 @@ razor_root_create(const char *root) path = razor_concat(root, file, NULL); retval = !stat(path, &buf); if (retval) { - fprintf(stderr, - "a razor install root is already initialized\n"); + razor_set_error(error, NULL, + "A razor install root is already initialized"); free(path); free(file); return retval; @@ -124,7 +120,8 @@ razor_root_create(const char *root) free(file); retval = razor_atomic_commit(atomic); if (retval) - fprintf(stderr, "could not write initial package set\n"); + razor_set_error(error, NULL, + "Could not write initial package set"); razor_set_unref(set); razor_atomic_destroy(atomic); diff --git a/src/main.c b/src/main.c index 0bc59ee..d406880 100644 --- a/src/main.c +++ b/src/main.c @@ -1214,7 +1214,17 @@ command_install(int argc, const char *argv[]) static int command_init(int argc, const char *argv[]) { - return razor_root_create(install_root); + int retval; + struct razor_error *error = NULL; + + retval = razor_root_create(install_root, &error); + if (retval) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); + } else + printf("Created install root\n"); + + return retval; } static int diff --git a/src/rpm.c b/src/rpm.c index 2277653..87cea8f 100644 --- a/src/rpm.c +++ b/src/rpm.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 @@ -253,7 +253,13 @@ static const char *repo_filename = system_repo_filename; static void command_initdb(int argc, const char *argv[]) { - razor_root_create(option_root); + struct razor_error *error = NULL; + + if (razor_root_create(option_root, &error)) { + fprintf(stderr, "%s\n", razor_error_get_msg(error)); + razor_error_free(error); + } else + printf("Created install root\n"); } static struct razor_property * -- 1.7.1