razor_create_root() should take an error pointer
authorJ. Ali Harlow <ali@juiblex.co.uk>
Thu Feb 16 17:44:25 2012 +0000 (2012-02-16)
changeset 4250c8bdd8dc942
parent 424 8cbc438cc298
child 426 2e896ad9754b
razor_create_root() should take an error pointer
librazor/razor.h
librazor/root.c
src/main.c
src/rpm.c
     1.1 --- a/librazor/razor.h	Thu Feb 16 17:33:47 2012 +0000
     1.2 +++ b/librazor/razor.h	Thu Feb 16 17:44:25 2012 +0000
     1.3 @@ -545,7 +545,7 @@
     1.4   **/
     1.5  struct razor_root;
     1.6  
     1.7 -int razor_root_create(const char *root);
     1.8 +int razor_root_create(const char *root, struct razor_error **error);
     1.9  struct razor_root *
    1.10  razor_root_open(const char *root, struct razor_error **error);
    1.11  struct razor_set *
     2.1 --- a/librazor/root.c	Thu Feb 16 17:33:47 2012 +0000
     2.2 +++ b/librazor/root.c	Thu Feb 16 17:44:25 2012 +0000
     2.3 @@ -77,7 +77,7 @@
     2.4  }
     2.5  
     2.6  RAZOR_EXPORT int
     2.7 -razor_root_create(const char *root)
     2.8 +razor_root_create(const char *root, struct razor_error **error)
     2.9  {
    2.10  	int retval;
    2.11  	struct stat buf;
    2.12 @@ -92,16 +92,12 @@
    2.13  		/* root is file system root */
    2.14  	} else if (stat(root, &buf) < 0) {
    2.15  		if (mkdir(root, 0777) < 0) {
    2.16 -			fprintf(stderr,
    2.17 -				"could not create install root \"%s\"\n",
    2.18 -				root);
    2.19 +			razor_set_error(error, root,
    2.20 +					"Could not create install root");
    2.21  			return -1;
    2.22  		}
    2.23 -		fprintf(stderr, "created install root \"%s\"\n", root);
    2.24  	} else if (!S_ISDIR(buf.st_mode)) {
    2.25 -		fprintf(stderr,
    2.26 -			"install root \"%s\" exists, but is not a directory\n",
    2.27 -			root);
    2.28 +		razor_set_error(error, root, "Not a directory");
    2.29  		return -1;
    2.30  	}
    2.31  
    2.32 @@ -109,8 +105,8 @@
    2.33  	path = razor_concat(root, file, NULL);
    2.34  	retval = !stat(path, &buf);
    2.35  	if (retval) {
    2.36 -		fprintf(stderr,
    2.37 -			"a razor install root is already initialized\n");
    2.38 +		razor_set_error(error, NULL,
    2.39 +				"A razor install root is already initialized");
    2.40  		free(path);
    2.41  		free(file);
    2.42  		return retval;
    2.43 @@ -124,7 +120,8 @@
    2.44  	free(file);
    2.45  	retval = razor_atomic_commit(atomic);
    2.46  	if (retval)
    2.47 -		fprintf(stderr, "could not write initial package set\n");
    2.48 +		razor_set_error(error, NULL,
    2.49 +				"Could not write initial package set");
    2.50  	razor_set_unref(set);
    2.51  	razor_atomic_destroy(atomic);
    2.52  
     3.1 --- a/src/main.c	Thu Feb 16 17:33:47 2012 +0000
     3.2 +++ b/src/main.c	Thu Feb 16 17:44:25 2012 +0000
     3.3 @@ -1214,7 +1214,17 @@
     3.4  static int
     3.5  command_init(int argc, const char *argv[])
     3.6  {
     3.7 -	return razor_root_create(install_root);
     3.8 +	int retval;
     3.9 +	struct razor_error *error = NULL;
    3.10 +
    3.11 +	retval = razor_root_create(install_root, &error);
    3.12 +	if (retval) {
    3.13 +		fprintf(stderr, "%s\n", razor_error_get_msg(error));
    3.14 +		razor_error_free(error);
    3.15 +	} else
    3.16 +		printf("Created install root\n");
    3.17 +
    3.18 +	return retval;
    3.19  }
    3.20  
    3.21  static int
     4.1 --- a/src/rpm.c	Thu Feb 16 17:33:47 2012 +0000
     4.2 +++ b/src/rpm.c	Thu Feb 16 17:44:25 2012 +0000
     4.3 @@ -1,7 +1,7 @@
     4.4  /*
     4.5   * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     4.6   * Copyright (C) 2008  Red Hat, Inc
     4.7 - * Copyright (C) 2009, 2011  J. Ali Harlow <ali@juiblex.co.uk>
     4.8 + * Copyright (C) 2009, 2011, 2012  J. Ali Harlow <ali@juiblex.co.uk>
     4.9   *
    4.10   * This program is free software; you can redistribute it and/or modify
    4.11   * it under the terms of the GNU General Public License as published by
    4.12 @@ -253,7 +253,13 @@
    4.13  static void
    4.14  command_initdb(int argc, const char *argv[])
    4.15  {
    4.16 -	razor_root_create(option_root);
    4.17 +	struct razor_error *error = NULL;
    4.18 +
    4.19 +	if (razor_root_create(option_root, &error)) {
    4.20 +		fprintf(stderr, "%s\n", razor_error_get_msg(error));
    4.21 +		razor_error_free(error);
    4.22 +	} else
    4.23 +		printf("Created install root\n");
    4.24  }
    4.25  
    4.26  static struct razor_property *