1.1 --- a/librazor/root.c Sat Aug 23 16:07:09 2014 +0100
1.2 +++ b/librazor/root.c Mon Sep 08 10:26:39 2014 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
1.6 * Copyright (C) 2008 Red Hat, Inc
1.7 - * Copyright (C) 2009, 2011, 2012 J. Ali Harlow <ali@juiblex.co.uk>
1.8 + * Copyright (C) 2009, 2011, 2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or modify
1.11 * it under the terms of the GNU General Public License as published by
1.12 @@ -41,6 +41,14 @@
1.13 #define O_BINARY 0
1.14 #endif
1.15
1.16 +#ifndef FALSE
1.17 +#define FALSE 0
1.18 +#endif
1.19 +
1.20 +#ifndef TRUE
1.21 +#define TRUE (!FALSE)
1.22 +#endif
1.23 +
1.24 static const char system_repo_filename[] = "system.rzdb";
1.25 /*
1.26 * system_lock_filename is chosen to be the same as the pre v0.3
1.27 @@ -50,11 +58,12 @@
1.28 */
1.29 static const char system_lock_filename[] = "system-next.rzdb";
1.30 #ifdef MSWIN_API
1.31 -#define RAZOR_ROOT_PATH NULL
1.32 +#define RAZOR_DATABASE_PATH NULL
1.33 #else
1.34 -#define RAZOR_ROOT_PATH "/var/lib/razor"
1.35 +#define RAZOR_DATABASE_PATH "/var/lib/razor"
1.36 #endif
1.37 -static const char *razor_root_path = RAZOR_ROOT_PATH;
1.38 +static char *razor_database_path = RAZOR_DATABASE_PATH;
1.39 +static int razor_database_path_alloced = FALSE;
1.40
1.41 struct razor_root {
1.42 struct razor_set *system;
1.43 @@ -65,17 +74,41 @@
1.44 razor_root_init(void)
1.45 {
1.46 #ifdef MSWIN_API
1.47 - static char root_path[MAX_PATH];
1.48 - if (!razor_root_path) {
1.49 + static char database_path[MAX_PATH];
1.50 + if (!razor_database_path) {
1.51 SHGetFolderPath(NULL,
1.52 CSIDL_COMMON_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, 0,
1.53 - root_path);
1.54 - strcat(root_path, "\\Razor");
1.55 - razor_root_path = root_path;
1.56 + database_path);
1.57 + strcat(database_path, "\\Razor");
1.58 + razor_database_path = database_path;
1.59 + razor_database_path_alloced = FALSE;
1.60 }
1.61 #endif
1.62 }
1.63
1.64 +RAZOR_EXPORT const char *
1.65 +razor_get_database_path()
1.66 +{
1.67 + razor_root_init();
1.68 +
1.69 + return razor_database_path;
1.70 +}
1.71 +
1.72 +RAZOR_EXPORT void
1.73 +razor_set_database_path(const char *database_path)
1.74 +{
1.75 + if (razor_database_path_alloced)
1.76 + free(razor_database_path);
1.77 +
1.78 + if (database_path) {
1.79 + razor_database_path = strdup(database_path);
1.80 + razor_database_path_alloced = TRUE;
1.81 + } else {
1.82 + razor_database_path = RAZOR_DATABASE_PATH;
1.83 + razor_database_path_alloced = FALSE;
1.84 + }
1.85 +}
1.86 +
1.87 RAZOR_EXPORT int
1.88 razor_root_create(const char *root, struct razor_error **error)
1.89 {
1.90 @@ -101,7 +134,8 @@
1.91 return -1;
1.92 }
1.93
1.94 - file = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
1.95 + file = razor_concat(razor_database_path, "/", system_repo_filename,
1.96 + NULL);
1.97 path = razor_path_add_root(file, root);
1.98 retval = !stat(path, &buf);
1.99 if (retval) {
1.100 @@ -152,7 +186,7 @@
1.101 return NULL;
1.102 }
1.103
1.104 - s = razor_concat(razor_root_path, "/", system_lock_filename, NULL);
1.105 + s = razor_concat(razor_database_path, "/", system_lock_filename, NULL);
1.106 lock_path = razor_path_add_root(s, root);
1.107 free(s);
1.108
1.109 @@ -168,7 +202,7 @@
1.110 return NULL;
1.111 }
1.112
1.113 - s = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
1.114 + s = razor_concat(razor_database_path, "/", system_repo_filename, NULL);
1.115 image->path = razor_path_add_root(s, root);
1.116 free(s);
1.117
1.118 @@ -198,7 +232,7 @@
1.119 return NULL;
1.120 }
1.121
1.122 - s = razor_concat(razor_root_path, "/", system_lock_filename, NULL);
1.123 + s = razor_concat(razor_database_path, "/", system_lock_filename, NULL);
1.124 path = razor_path_add_root(s, root);
1.125 free(s);
1.126
1.127 @@ -212,7 +246,7 @@
1.128
1.129 free(path);
1.130
1.131 - s = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
1.132 + s = razor_concat(razor_database_path, "/", system_repo_filename, NULL);
1.133 path = razor_path_add_root(s, root);
1.134 free(s);
1.135