Permalink
Browse files

Convert main.c to use razor_root for most cases.

With this we change the default repo location to /var/lib/razor, but let the env
variable RAZOR_ROOT override it.
  • Loading branch information...
1 parent 9349887 commit 48047240d3157ef9f8525ccd9d5c2342eb10abc6 Kristian Høgsberg committed Jul 9, 2008
Showing with 76 additions and 30 deletions.
  1. +41 −3 librazor/root.c
  2. +35 −27 src/main.c
View
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
@@ -40,6 +41,7 @@ struct razor_root {
struct razor_set *system;
struct razor_set *next;
int fd;
+ char root[PATH_MAX];
char path[PATH_MAX];
char new_path[PATH_MAX];
};
@@ -53,7 +55,9 @@ razor_root_create(const char *root)
assert (root != NULL);
- if (stat(root, &buf) < 0) {
+ if (root[0] == '\0') {
+ /* 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",
@@ -136,6 +140,10 @@ razor_root_open(const char *root)
snprintf(files_path, sizeof files_path,
"%s%s/%s", root, razor_root_path, system_repo_files_filename);
+ /* FIXME: We store the root path to make the hack in
+ * razor_root_update() work. Need to get rid of this. */
+ strcpy(image->root, root);
+
image->system = razor_set_open(image->path);
if (image->system == NULL ||
razor_set_open_details(image->system, details_path) ||
@@ -152,14 +160,30 @@ razor_root_open(const char *root)
RAZOR_EXPORT struct razor_set *
razor_root_open_read_only(const char *root)
{
- char path[PATH_MAX];
+ char path[PATH_MAX], details_path[PATH_MAX], files_path[PATH_MAX];
+ struct razor_set *set;
assert (root != NULL);
snprintf(path, sizeof path, "%s%s/%s",
root, razor_root_path, system_repo_filename);
+ snprintf(details_path, sizeof details_path,
+ "%s%s/%s", root, razor_root_path, system_repo_details_filename);
+ snprintf(files_path, sizeof files_path,
+ "%s%s/%s", root, razor_root_path, system_repo_files_filename);
+
- return razor_set_open(path);
+ set = razor_set_open(path);
+ if (set == NULL)
+ return NULL;
+
+ if (razor_set_open_details(set, details_path) ||
+ razor_set_open_files(set, files_path)) {
+ razor_set_destroy(set);
+ return NULL;
+ }
+
+ return set;
}
RAZOR_EXPORT struct razor_set *
@@ -186,12 +210,26 @@ razor_root_close(struct razor_root *root)
RAZOR_EXPORT void
razor_root_update(struct razor_root *root, struct razor_set *next)
{
+ char path[PATH_MAX];
+
assert (root != NULL);
assert (next != NULL);
razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN);
root->next = next;
+ /* FIXME: This is a pretty bad hack that just overwrites the
+ * system details and files rzdb files before the transaction
+ * succeeds. We need to fix this by merging the separate
+ * details and files rzdb files back into the main rzdb
+ * file. */
+ snprintf(path, sizeof path,
+ "%s%s/%s", root->root, razor_root_path, system_repo_details_filename);
+ razor_set_write(next, path, RAZOR_REPO_FILE_DETAILS);
+ snprintf(path, sizeof path,
+ "%s%s/%s", root->root, razor_root_path, system_repo_files_filename);
+ razor_set_write(next, path, RAZOR_REPO_FILE_FILES);
+
/* Sync the new repo file so the new package set is on disk
* before we start upgrading. */
fsync(root->fd);
View
@@ -37,7 +37,7 @@ static const char system_repo_filename[] = "system.rzdb";
static const char next_repo_filename[] = "system-next.rzdb";
static const char rawhide_repo_filename[] = "rawhide.rzdb";
static const char updated_repo_filename[] = "system-updated.rzdb";
-static const char install_root[] = "install";
+static const char *install_root = "";
static const char *repo_filename = system_repo_filename;
static const char *yum_url;
@@ -113,7 +113,10 @@ command_list(int argc, const char *argv[])
i++;
}
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
+ if (set == NULL)
+ return 1;
+
pi = create_iterator_from_argv(set, argc - i, argv + i);
list_packages(pi, flags);
razor_package_iterator_destroy(pi);
@@ -167,7 +170,10 @@ list_properties(int argc, const char *argv[], uint32_t type)
struct razor_package_iterator *pi;
const char *name, *version, *arch;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
+ if (set == NULL)
+ return 1;
+
pi = create_iterator_from_argv(set, argc, argv);
while (razor_package_iterator_next(pi, &package,
RAZOR_DETAIL_NAME, &name,
@@ -210,9 +216,10 @@ command_list_files(int argc, const char *argv[])
{
struct razor_set *set;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
if (set == NULL)
return 1;
+
if (razor_set_open_files(set, "system-files.rzdb"))
return 1;
@@ -228,11 +235,9 @@ command_list_file_packages(int argc, const char *argv[])
struct razor_set *set;
struct razor_package_iterator *pi;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
if (set == NULL)
return 1;
- if (razor_set_open_files(set, "system-files.rzdb"))
- return 1;
pi = razor_package_iterator_create_for_file(set, argv[0]);
list_packages(pi, 0);
@@ -251,11 +256,9 @@ command_list_package_files(int argc, const char *argv[])
struct razor_package *package;
const char *name, *version, *arch;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
if (set == NULL)
return 1;
- if (razor_set_open_files(set, "system-files.rzdb"))
- return 1;
pi = create_iterator_from_argv(set, argc, argv);
while (razor_package_iterator_next(pi, &package,
@@ -286,7 +289,7 @@ list_property_packages(const char *ref_name,
if (ref_name == NULL)
return 0;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
if (set == NULL)
return 1;
@@ -310,6 +313,8 @@ list_property_packages(const char *ref_name,
}
razor_property_iterator_destroy(prop_iter);
+ razor_set_destroy(set);
+
return 0;
}
@@ -430,17 +435,19 @@ static int
command_import_rpmdb(int argc, const char *argv[])
{
struct razor_set *set;
+ struct razor_root *root;
+
+ root = razor_root_open(install_root);
+ if (root == NULL)
+ return 1;
set = razor_set_create_from_rpmdb();
if (set == NULL)
return 1;
- razor_set_write(set, repo_filename, RAZOR_REPO_FILE_MAIN);
- razor_set_write(set, "system-details.rzdb", RAZOR_REPO_FILE_DETAILS);
- razor_set_write(set, "system-files.rzdb", RAZOR_REPO_FILE_FILES);
- razor_set_destroy(set);
- printf("wrote %s\n", repo_filename);
- return 0;
+ razor_root_update(root, set);
+
+ return razor_root_commit(root);
}
static int
@@ -496,10 +503,8 @@ command_update(int argc, const char *argv[])
struct razor_transaction *trans;
int i, errors;
- set = razor_set_open(repo_filename);
- if (set == NULL ||
- razor_set_open_details(set, "system-details.rzdb") ||
- razor_set_open_files(set, "system-files.rzdb"))
+ set = razor_root_open_read_only(install_root);
+ if (set == NULL)
return 1;
upstream = razor_set_open(rawhide_repo_filename);
@@ -541,7 +546,7 @@ command_remove(int argc, const char *argv[])
struct razor_transaction *trans;
int i, errors;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
if (set == NULL)
return 1;
@@ -586,7 +591,7 @@ command_diff(int argc, const char *argv[])
{
struct razor_set *set, *updated;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
updated = razor_set_open(updated_repo_filename);
if (set == NULL || updated == NULL)
return 1;
@@ -896,11 +901,10 @@ command_info(int argc, const char *argv[])
const char *pattern = argv[0], *name, *version, *arch;
const char *summary, *description, *url, *license;
- set = razor_set_open(repo_filename);
+ set = razor_root_open_read_only(install_root);
if (set == NULL)
return 1;
- if (razor_set_open_details(set, "system-details.rzdb"))
- return 1;
+
pi = razor_package_iterator_create(set);
while (razor_package_iterator_next(pi, &package,
RAZOR_DETAIL_NAME, &name,
@@ -1025,13 +1029,17 @@ usage(void)
int
main(int argc, const char *argv[])
{
- char *repo;
+ char *repo, *root;
int i;
repo = getenv("RAZOR_REPO");
if (repo != NULL)
repo_filename = repo;
+ root = getenv("RAZOR_ROOT");
+ if (root != NULL)
+ install_root = root;
+
yum_url = getenv("YUM_URL");
if (yum_url == NULL)
yum_url = YUM_URL;

0 comments on commit 4804724

Please sign in to comment.