# HG changeset patch # User J. Ali Harlow # Date 1329414265 0 # Node ID 0c8bdd8dc94291e2d09df3a6652135d4daa78bdd # Parent 8cbc438cc298e9ae2deb6e00d54eb9310df2e351 razor_create_root() should take an error pointer diff -r 8cbc438cc298 -r 0c8bdd8dc942 librazor/razor.h --- a/librazor/razor.h Thu Feb 16 17:33:47 2012 +0000 +++ b/librazor/razor.h Thu Feb 16 17:44:25 2012 +0000 @@ -545,7 +545,7 @@ **/ 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 -r 8cbc438cc298 -r 0c8bdd8dc942 librazor/root.c --- a/librazor/root.c Thu Feb 16 17:33:47 2012 +0000 +++ b/librazor/root.c Thu Feb 16 17:44:25 2012 +0000 @@ -77,7 +77,7 @@ } 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 @@ /* 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 @@ 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 @@ 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 -r 8cbc438cc298 -r 0c8bdd8dc942 src/main.c --- a/src/main.c Thu Feb 16 17:33:47 2012 +0000 +++ b/src/main.c Thu Feb 16 17:44:25 2012 +0000 @@ -1214,7 +1214,17 @@ 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 -r 8cbc438cc298 -r 0c8bdd8dc942 src/rpm.c --- a/src/rpm.c Thu Feb 16 17:33:47 2012 +0000 +++ b/src/rpm.c Thu Feb 16 17:44:25 2012 +0000 @@ -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 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 *