}
RAZOR_EXPORT int
-razor_root_create(const char *root)
+razor_root_create(const char *root, struct razor_error **error)
{
int retval;
struct stat buf;
/* 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;
}
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;
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);
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
/*
* 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
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 *