1.1 --- a/librazor/root.c Wed Jan 07 17:59:12 2009 +0000
1.2 +++ b/librazor/root.c Fri Jan 09 15:28:50 2009 +0000
1.3 @@ -1,6 +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 J. Ali Harlow <ali@juiblex.co.uk>
1.8 *
1.9 * This program is free software; you can redistribute it and/or modify
1.10 * it under the terms of the GNU General Public License as published by
1.11 @@ -17,6 +18,8 @@
1.12 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.13 */
1.14
1.15 +#include "config.h"
1.16 +
1.17 #include <stdlib.h>
1.18 #include <stdint.h>
1.19 #include <stdio.h>
1.20 @@ -27,6 +30,9 @@
1.21 #include <fcntl.h>
1.22 #include <limits.h>
1.23 #include <assert.h>
1.24 +#ifdef MSWIN_API
1.25 +#include <shlobj.h>
1.26 +#endif
1.27
1.28 #include "razor.h"
1.29 #include "razor-internal.h"
1.30 @@ -36,7 +42,12 @@
1.31 static const char system_repo_files_filename[] = "system-files.rzdb";
1.32
1.33 static const char next_repo_filename[] = "system-next.rzdb";
1.34 -static const char razor_root_path[] = "/var/lib/razor";
1.35 +#ifdef MSWIN_API
1.36 +#define RAZOR_ROOT_PATH NULL
1.37 +#else
1.38 +#define RAZOR_ROOT_PATH "/var/lib/razor"
1.39 +#endif
1.40 +static const char *razor_root_path = RAZOR_ROOT_PATH;
1.41
1.42 struct razor_root {
1.43 struct razor_set *system;
1.44 @@ -47,6 +58,21 @@
1.45 char new_path[PATH_MAX];
1.46 };
1.47
1.48 +static void
1.49 +razor_root_init(void)
1.50 +{
1.51 +#ifdef MSWIN_API
1.52 + static char root_path[MAX_PATH];
1.53 + if (!razor_root_path) {
1.54 + SHGetFolderPath(NULL,
1.55 + CSIDL_COMMON_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, 0,
1.56 + root_path);
1.57 + strcat(root_path, "\\Razor");
1.58 + razor_root_path = root_path;
1.59 + }
1.60 +#endif
1.61 +}
1.62 +
1.63 RAZOR_EXPORT int
1.64 razor_root_create(const char *root)
1.65 {
1.66 @@ -56,6 +82,7 @@
1.67
1.68 assert (root != NULL);
1.69
1.70 + razor_root_init();
1.71 if (root[0] == '\0') {
1.72 /* root is file system root */
1.73 } else if (stat(root, &buf) < 0) {
1.74 @@ -112,6 +139,7 @@
1.75
1.76 assert (root != NULL);
1.77
1.78 + razor_root_init();
1.79 image = malloc(sizeof *image);
1.80 if (image == NULL)
1.81 return NULL;
1.82 @@ -166,6 +194,7 @@
1.83
1.84 assert (root != NULL);
1.85
1.86 + razor_root_init();
1.87 snprintf(path, sizeof path, "%s%s/%s",
1.88 root, razor_root_path, system_repo_filename);
1.89 snprintf(details_path, sizeof details_path,
1.90 @@ -216,6 +245,7 @@
1.91 assert (root != NULL);
1.92 assert (next != NULL);
1.93
1.94 + razor_root_init();
1.95 razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN);
1.96 root->next = next;
1.97