Fix a bug causing libtool versioning to be ignored.
This bug meant that razor 0.1 was recorded as interface 0 rather
than the intended interface 1. razor 0.2 will use interface 1.
2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 #include "razor-internal.h"
44 static const char system_repo_filename[] = "system.rzdb";
45 static const char next_repo_filename[] = "system-next.rzdb";
47 #define RAZOR_ROOT_PATH NULL
49 #define RAZOR_ROOT_PATH "/var/lib/razor"
51 static const char *razor_root_path = RAZOR_ROOT_PATH;
54 struct razor_set *system;
55 struct razor_set *next;
58 char new_path[PATH_MAX];
65 static char root_path[MAX_PATH];
66 if (!razor_root_path) {
68 CSIDL_COMMON_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, 0,
70 strcat(root_path, "\\Razor");
71 razor_root_path = root_path;
77 razor_root_create(const char *root)
80 struct razor_set *set;
83 assert (root != NULL);
86 if (root[0] == '\0') {
87 /* root is file system root */
88 } else if (stat(root, &buf) < 0) {
89 if (mkdir(root, 0777) < 0) {
91 "could not create install root \"%s\"\n",
95 fprintf(stderr, "created install root \"%s\"\n", root);
96 } else if (!S_ISDIR(buf.st_mode)) {
98 "install root \"%s\" exists, but is not a directory\n",
103 snprintf(path, sizeof path, "%s/%s",
104 razor_root_path, system_repo_filename);
105 if (razor_create_dir(root, path) < 0) {
106 fprintf(stderr, "could not create %s%s\n",
107 root, razor_root_path);
111 set = razor_set_create();
112 snprintf(path, sizeof path, "%s%s/%s",
113 root, razor_root_path, system_repo_filename);
114 if (stat(path, &buf) == 0) {
116 "a razor install root is already initialized\n");
119 if (razor_set_write(set, path, RAZOR_SECTION_ALL) < 0) {
120 fprintf(stderr, "could not write initial package set\n");
123 razor_set_destroy(set);
128 RAZOR_EXPORT struct razor_root *
129 razor_root_open(const char *root)
131 struct razor_root *image;
133 assert (root != NULL);
136 image = malloc(sizeof *image);
140 /* Create the new next repo file up front to ensure exclusive
142 snprintf(image->new_path, sizeof image->new_path,
143 "%s%s/%s", root, razor_root_path, next_repo_filename);
144 image->fd = open(image->new_path,
145 O_CREAT | O_WRONLY | O_TRUNC | O_EXCL | O_BINARY,
148 fprintf(stderr, "failed to get lock file, "
149 "maybe previous operation crashed?\n");
151 /* FIXME: Use fcntl advisory locking on the system
152 * package set file to figure out whether previous
153 * operation crashed or is still in progress. */
159 snprintf(image->path, sizeof image->path,
160 "%s%s/%s", root, razor_root_path, system_repo_filename);
162 image->system = razor_set_open(image->path);
163 if (image->system == NULL) {
164 unlink(image->new_path);
173 RAZOR_EXPORT struct razor_set *
174 razor_root_open_read_only(const char *root)
178 assert (root != NULL);
181 snprintf(path, sizeof path, "%s%s/%s",
182 root, razor_root_path, system_repo_filename);
184 return razor_set_open(path);
187 RAZOR_EXPORT struct razor_set *
188 razor_root_get_system_set(struct razor_root *root)
190 assert (root != NULL);
196 razor_root_close(struct razor_root *root)
198 assert (root != NULL);
200 razor_set_destroy(root->system);
202 unlink(root->new_path);
209 razor_root_update(struct razor_root *root, struct razor_set *next)
211 assert (root != NULL);
212 assert (next != NULL);
215 razor_set_write_to_fd(next, root->fd, RAZOR_SECTION_ALL);
218 /* Sync the new repo file so the new package set is on disk
219 * before we start upgrading. */
221 printf("wrote %s\n", root->new_path);
225 razor_root_commit(struct razor_root *root)
228 assert (root != NULL);
233 /* Rename is not atomic under MS-Windows */
236 retval = rename(root->new_path, root->path);
240 printf("renamed %s to %s\n", root->new_path, root->path);
241 razor_set_destroy(root->system);