Use GCC 4 -fvisibility to control exported symbols.
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, RAZOR_REPO_FILE_MAIN) < 0) {
62 fprintf(stderr, "could not write initial package set\n");
65 razor_set_destroy(set);
70 RAZOR_EXPORT struct razor_root *
71 razor_root_open(const char *root)
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, razor_root_path, 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);
110 RAZOR_EXPORT struct razor_set *
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 RAZOR_EXPORT struct razor_set *
122 razor_root_get_system_set(struct razor_root *root)
128 razor_root_close(struct razor_root *root)
130 razor_set_destroy(root->system);
131 unlink(root->new_path);
139 razor_root_update(struct razor_root *root, struct razor_set *next)
141 razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN);
144 /* Sync the new repo file so the new package set is on disk
145 * before we start upgrading. */
147 printf("wrote %s\n", root->new_path);
151 razor_root_commit(struct razor_root *root)
154 rename(root->new_path, root->path);
155 printf("renamed %s to %s\n", root->new_path, root->path);
156 razor_set_destroy(root->system);