#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
struct razor_set *system;
struct razor_set *next;
int fd;
+ char root[PATH_MAX];
char path[PATH_MAX];
char new_path[PATH_MAX];
};
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",
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) ||
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 *
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);
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;
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);
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,
{
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;
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);
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,
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;
}
razor_property_iterator_destroy(prop_iter);
+ razor_set_destroy(set);
+
return 0;
}
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
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);
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;
{
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;
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,
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;