Add -lole32 to link libraries.
This fixes a problem when compiling with mingw-headers version 3.3
where the use of SHGetFolderPath() expands to a call to CoTaskMemFree()
which is defined in libole32.dll:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/shobjidl.h:29954: undefined reference to `__imp_CoTaskMemFree'
2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
4 * Copyright (C) 2009, 2011, 2012, 2014 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.
39 #include "razor-internal.h"
53 static const char system_repo_filename[] = "system.rzdb";
55 * system_lock_filename is chosen to be the same as the pre v0.3
56 * next_repo_filename. This means that once a system has been
57 * updated by a v0.3+ copy of razor all pre v0.3 versions of razor
58 * will see the system as permenantly locked.
60 static const char system_lock_filename[] = "system-next.rzdb";
62 #define RAZOR_DATABASE_PATH NULL
64 #define RAZOR_DATABASE_PATH "/var/lib/razor"
66 static char *razor_database_path = RAZOR_DATABASE_PATH;
67 static int razor_database_path_alloced = FALSE;
70 struct razor_set *system;
78 static char database_path[MAX_PATH];
79 if (!razor_database_path) {
81 CSIDL_COMMON_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, 0,
83 strcat(database_path, "\\Razor");
84 razor_database_path = database_path;
85 razor_database_path_alloced = FALSE;
90 RAZOR_EXPORT const char *
91 razor_get_database_path()
95 return razor_database_path;
99 razor_set_database_path(const char *database_path)
101 if (razor_database_path_alloced)
102 free(razor_database_path);
105 razor_database_path = strdup(database_path);
106 razor_database_path_alloced = TRUE;
108 razor_database_path = RAZOR_DATABASE_PATH;
109 razor_database_path_alloced = FALSE;
114 razor_root_create(const char *root, struct razor_error **error)
118 struct razor_set *set;
119 struct razor_atomic *atomic;
122 assert (root != NULL);
125 if (root[0] == '\0') {
126 /* root is file system root */
127 } else if (stat(root, &buf) < 0) {
128 if (mkdir(root, 0777) < 0) {
129 razor_set_error(error, RAZOR_POSIX_ERROR, errno, root,
130 "Could not create install root");
133 } else if (!S_ISDIR(buf.st_mode)) {
134 razor_set_error(error, RAZOR_POSIX_ERROR, ENOTDIR, root,
139 file = razor_concat(razor_database_path, "/", system_repo_filename,
141 path = razor_path_add_root(file, root);
142 retval = !stat(path, &buf);
144 razor_set_error(error, RAZOR_GENERAL_ERROR,
145 RAZOR_GENERAL_ERROR_DATABASE_EXISTS, NULL,
146 "A razor install root is already initialized");
152 atomic = razor_atomic_open("Create initial package set");
153 razor_atomic_make_dirs(atomic, root, file);
154 set = razor_set_create();
155 razor_set_write(set, atomic, path, RAZOR_SECTION_ALL);
158 retval = razor_atomic_commit(atomic);
160 razor_propagate_error(error,
161 razor_atomic_get_error(atomic),
162 "Could not write initial package set");
163 razor_set_unref(set);
164 razor_atomic_destroy(atomic);
169 RAZOR_EXPORT struct razor_root *
170 razor_root_open(const char *root, struct razor_error **error)
172 struct razor_root *image;
176 assert (root != NULL);
179 image = malloc(sizeof *image);
181 razor_set_error(error, RAZOR_POSIX_ERROR, ENOMEM, NULL,
182 "Not enough memory");
186 image->system = razor_set_create_without_root();
187 if (image->system == NULL) {
189 razor_set_error(error, RAZOR_POSIX_ERROR, ENOMEM, NULL,
190 "Not enough memory");
194 s = razor_concat(razor_database_path, "/", system_lock_filename, NULL);
195 lock_path = razor_path_add_root(s, root);
198 r = razor_set_aquire_lock(image->system, lock_path, 1);
203 razor_set_error(error, RAZOR_GENERAL_ERROR,
204 RAZOR_GENERAL_ERROR_DATABASE_LOCKED, NULL,
205 "Failed to aquire exclusive system lock");
206 razor_set_unref(image->system);
211 s = razor_concat(razor_database_path, "/", system_repo_filename, NULL);
212 image->path = razor_path_add_root(s, root);
215 if (razor_set_bind_sections(image->system, image->path,
216 RAZOR_SET_PRIVATE, error)) {
218 razor_set_unref(image->system);
226 RAZOR_EXPORT struct razor_set *
227 razor_root_open_read_only(const char *root, struct razor_error **error)
230 struct razor_set *set;
232 assert (root != NULL);
235 set = razor_set_create_without_root();
237 razor_set_error(error, RAZOR_POSIX_ERROR, ENOMEM, NULL,
238 "Not enough memory");
242 s = razor_concat(razor_database_path, "/", system_lock_filename, NULL);
243 path = razor_path_add_root(s, root);
246 if (razor_set_aquire_lock(set, path, 0) < 0) {
247 razor_set_error(error, RAZOR_GENERAL_ERROR,
248 RAZOR_GENERAL_ERROR_DATABASE_LOCKED, NULL,
249 "Failed to aquire non-exclusive system lock");
251 razor_set_unref(set);
257 s = razor_concat(razor_database_path, "/", system_repo_filename, NULL);
258 path = razor_path_add_root(s, root);
261 if (razor_set_bind_sections(set, path, 0, error)) {
262 razor_set_unref(set);
271 RAZOR_EXPORT struct razor_set *
272 razor_root_get_system_set(struct razor_root *root)
274 assert (root != NULL);
280 razor_root_close(struct razor_root *root)
282 assert (root != NULL);
284 razor_set_unref(root->system);
292 razor_root_update(struct razor_root *root, struct razor_set *next,
293 struct razor_atomic *atomic)
297 assert (root != NULL);
298 assert (next != NULL);
300 handle = razor_atomic_create_file(atomic, root->path,
301 S_IRWXU | S_IRWXG | S_IRWXO);
305 razor_set_write_to_handle(next, atomic, handle, RAZOR_SECTION_ALL);
307 retval = razor_atomic_close(atomic, handle);
310 razor_set_unref(root->system);
311 root->system = razor_set_ref(next);