Add spec file.
committer: Kristian H?gsberg <krh@redhat.com>
9 #include "razor-internal.h"
11 static const char system_repo_filename[] = "system.repo";
12 static const char next_repo_filename[] = "system-next.repo";
13 static const char razor_root_path[] = "/var/lib/razor";
16 struct razor_set *system;
17 struct razor_set *next;
20 char new_path[PATH_MAX];
24 razor_root_create(const char *root)
27 struct razor_set *set;
30 if (stat(root, &buf) < 0) {
31 if (mkdir(root, 0777) < 0) {
33 "could not create install root \"%s\"\n",
37 fprintf(stderr, "created install root \"%s\"\n", root);
38 } else if (!S_ISDIR(buf.st_mode)) {
40 "install root \"%s\" exists, but is not a directory\n",
45 snprintf(path, sizeof path, "%s/%s",
46 razor_root_path, system_repo_filename);
47 if (razor_create_dir(root, path) < 0) {
48 fprintf(stderr, "could not create %s%s\n",
49 root, razor_root_path);
53 set = razor_set_create();
54 snprintf(path, sizeof path, "%s%s/%s",
55 root, razor_root_path, system_repo_filename);
56 if (stat(path, &buf) == 0) {
58 "a razor install root is already initialized\n");
61 if (razor_set_write(set, path) < 0) {
62 fprintf(stderr, "could not write initial package set\n");
65 razor_set_destroy(set);
71 razor_root_open(const char *root, int flags)
73 struct razor_root *image;
75 image = malloc(sizeof *image);
79 /* Create the new next repo file up front to ensure exclusive
81 snprintf(image->new_path, sizeof image->new_path,
82 "%s%s/%s", root, root, next_repo_filename);
83 image->fd = open(image->new_path,
84 O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0666);
86 fprintf(stderr, "failed to get lock file, "
87 "maybe previous operation crashed?\n");
89 /* FIXME: Use fcntl advisory locking on the system
90 * package set file to figure out whether previous
91 * operation crashed or is still in progress. */
97 snprintf(image->path, sizeof image->path,
98 "%s%s/%s", root, razor_root_path, system_repo_filename);
99 image->system = razor_set_open(image->path);
100 if (image->system == NULL) {
101 unlink(image->new_path);
111 razor_root_open_read_only(const char *root)
115 snprintf(path, sizeof path, "%s%s/%s",
116 root, razor_root_path, system_repo_filename);
118 return razor_set_open(path);
121 struct razor_transaction *
122 razor_root_create_transaction(struct razor_root *image,
123 struct razor_set *upstream)
125 /* FIXME: This should take a number of upstream repos. */
126 return razor_transaction_create(image->system, upstream);
130 razor_root_close(struct razor_root *image)
132 unlink(image->new_path);
140 razor_root_update(struct razor_root *root, struct razor_set *next)
142 razor_set_write_to_fd(next, root->fd);
145 /* Sync the new repo file so the new package set is on disk
146 * before we start upgrading. */
148 printf("wrote %s\n", root->new_path);
152 razor_root_commit(struct razor_root *image)
155 rename(image->new_path, image->path);
156 printf("renamed %s to %s\n", image->new_path, image->path);
164 razor_root_diff(struct razor_root *root,
165 razor_package_callback_t callback, void *data)
167 return razor_set_diff(root->system, root->next, callback, data);