razor_create_root() should take an error pointer
authorJ. Ali Harlow <ali@juiblex.co.uk>
Thu, 16 Feb 2012 17:44:25 +0000 (17:44 +0000)
committerJ. Ali Harlow <ali@juiblex.co.uk>
Thu, 16 Feb 2012 17:44:25 +0000 (17:44 +0000)
librazor/razor.h
librazor/root.c
src/main.c
src/rpm.c

index 4988764..c004fcb 100644 (file)
@@ -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 *
index 180434d..f3992d3 100644 (file)
@@ -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);
 
index 0bc59ee..d406880 100644 (file)
@@ -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
index 2277653..87cea8f 100644 (file)
--- a/src/rpm.c
+++ b/src/rpm.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
  * Copyright (C) 2008  Red Hat, Inc
- * Copyright (C) 2009, 2011  J. Ali Harlow <ali@juiblex.co.uk>
+ * Copyright (C) 2009, 2011, 2012  J. Ali Harlow <ali@juiblex.co.uk>
  *
  * 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 *