librazor/root.c
changeset 319 ed8155380e45
parent 315 1c52b84bfc33
child 325 73393734833c
     1.1 --- a/librazor/root.c	Tue Jul 08 21:59:36 2008 -0400
     1.2 +++ b/librazor/root.c	Mon Jan 05 17:39:05 2009 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  #include <stdlib.h>
     1.5  #include <stdint.h>
     1.6  #include <stdio.h>
     1.7 +#include <string.h>
     1.8  #include <sys/stat.h>
     1.9  #include <dirent.h>
    1.10  #include <unistd.h>
    1.11 @@ -40,6 +41,7 @@
    1.12  	struct razor_set *system;
    1.13  	struct razor_set *next;
    1.14  	int fd;
    1.15 +	char root[PATH_MAX];
    1.16  	char path[PATH_MAX];
    1.17  	char new_path[PATH_MAX];
    1.18  };
    1.19 @@ -53,7 +55,9 @@
    1.20  
    1.21  	assert (root != NULL);
    1.22  
    1.23 -	if (stat(root, &buf) < 0) {
    1.24 +	if (root[0] == '\0') {
    1.25 +		/* root is file system root */
    1.26 +	} else if (stat(root, &buf) < 0) {
    1.27  		if (mkdir(root, 0777) < 0) {
    1.28  			fprintf(stderr,
    1.29  				"could not create install root \"%s\"\n",
    1.30 @@ -136,6 +140,10 @@
    1.31  	snprintf(files_path, sizeof files_path,
    1.32  		 "%s%s/%s", root, razor_root_path, system_repo_files_filename);
    1.33  
    1.34 +	/* FIXME: We store the root path to make the hack in
    1.35 +	 * razor_root_update() work.  Need to get rid of this. */
    1.36 +	strcpy(image->root, root);
    1.37 +
    1.38  	image->system = razor_set_open(image->path);
    1.39  	if (image->system == NULL ||
    1.40  	    razor_set_open_details(image->system, details_path) ||
    1.41 @@ -152,14 +160,30 @@
    1.42  RAZOR_EXPORT struct razor_set *
    1.43  razor_root_open_read_only(const char *root)
    1.44  {
    1.45 -	char path[PATH_MAX];
    1.46 +	char path[PATH_MAX], details_path[PATH_MAX], files_path[PATH_MAX];
    1.47 +	struct razor_set *set;
    1.48  
    1.49  	assert (root != NULL);
    1.50  
    1.51  	snprintf(path, sizeof path, "%s%s/%s",
    1.52  		 root, razor_root_path, system_repo_filename);
    1.53 +	snprintf(details_path, sizeof details_path,
    1.54 +		 "%s%s/%s", root, razor_root_path, system_repo_details_filename);
    1.55 +	snprintf(files_path, sizeof files_path,
    1.56 +		 "%s%s/%s", root, razor_root_path, system_repo_files_filename);
    1.57  
    1.58 -	return razor_set_open(path);
    1.59 +
    1.60 +	set = razor_set_open(path);
    1.61 +	if (set == NULL)
    1.62 +		return NULL;
    1.63 +
    1.64 +	if (razor_set_open_details(set, details_path) ||
    1.65 +	    razor_set_open_files(set, files_path)) {
    1.66 +		razor_set_destroy(set);
    1.67 +		return NULL;
    1.68 +	}
    1.69 +
    1.70 +	return set;
    1.71  }
    1.72  
    1.73  RAZOR_EXPORT struct razor_set *
    1.74 @@ -186,12 +210,26 @@
    1.75  RAZOR_EXPORT void
    1.76  razor_root_update(struct razor_root *root, struct razor_set *next)
    1.77  {
    1.78 +	char path[PATH_MAX];
    1.79 +
    1.80  	assert (root != NULL);
    1.81  	assert (next != NULL);
    1.82  
    1.83  	razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN);
    1.84  	root->next = next;
    1.85  
    1.86 +	/* FIXME: This is a pretty bad hack that just overwrites the
    1.87 +	 * system details and files rzdb files before the transaction
    1.88 +	 * succeeds.  We need to fix this by merging the separate
    1.89 +	 * details and files rzdb files back into the main rzdb
    1.90 +	 * file. */
    1.91 +	snprintf(path, sizeof path,
    1.92 +		 "%s%s/%s", root->root, razor_root_path, system_repo_details_filename);
    1.93 +	razor_set_write(next, path, RAZOR_REPO_FILE_DETAILS);
    1.94 +	snprintf(path, sizeof path,
    1.95 +		 "%s%s/%s", root->root, razor_root_path, system_repo_files_filename);
    1.96 +	razor_set_write(next, path, RAZOR_REPO_FILE_FILES);
    1.97 +
    1.98  	/* Sync the new repo file so the new package set is on disk
    1.99  	 * before we start upgrading. */
   1.100  	fsync(root->fd);