/*
- * Copyright (C) 2011-2012 J. Ali Harlow <ali@juiblex.co.uk>
+ * Copyright (C) 2011, 2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "razor.h"
#include "razor-internal.h"
-#define RAZOR_ASCII_ISALPHA(c) \
- ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z')
-
static int
razor_valid_root_name2(const wchar_t *name)
{
return -1;
buffer = razor_wstr_create(root, -1);
- slash = path;
+ slash = buffer->len ? SKIP_DRIVE_LETTER(path) : path;
for (; *slash != '\0'; slash = next) {
next = strpbrk(slash + 1, "/\\");
}
file = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
- path = razor_concat(root, file, NULL);
+ path = razor_path_add_root(file, root);
retval = !stat(path, &buf);
if (retval) {
razor_set_error(error, NULL,
razor_root_open(const char *root, struct razor_error **error)
{
struct razor_root *image;
- char *lock_path;
+ char *s, *lock_path;
int r;
assert (root != NULL);
return NULL;
}
- lock_path = razor_concat(root, razor_root_path, "/",
- system_lock_filename, NULL);
+ s = razor_concat(razor_root_path, "/", system_lock_filename, NULL);
+ lock_path = razor_path_add_root(s, root);
+ free(s);
r = razor_set_aquire_lock(image->system, lock_path, 1);
return NULL;
}
- image->path = razor_concat(root, razor_root_path, "/",
- system_repo_filename, NULL);
+ s = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
+ image->path = razor_path_add_root(s, root);
+ free(s);
if (razor_set_bind_sections(image->system, image->path,
RAZOR_SET_PRIVATE, error)) {
RAZOR_EXPORT struct razor_set *
razor_root_open_read_only(const char *root, struct razor_error **error)
{
- char *path;
+ char *s, *path;
struct razor_set *set;
assert (root != NULL);
return NULL;
}
- path = razor_concat(root, razor_root_path, "/", system_lock_filename,
- NULL);
+ s = razor_concat(razor_root_path, "/", system_lock_filename, NULL);
+ path = razor_path_add_root(s, root);
+ free(s);
+
if (razor_set_aquire_lock(set, path, 0) < 0) {
razor_set_error(error, NULL,
"Failed to aquire non-exclusive system lock");
}
free(path);
- path = razor_concat(root, razor_root_path, "/", system_repo_filename,
- NULL);
+
+ s = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
+ path = razor_path_add_root(s, root);
+ free(s);
if (razor_set_bind_sections(set, path, 0, error)) {
razor_set_unref(set);
/*
* Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
* Copyright (C) 2008 Red Hat, Inc
- * Copyright (C) 2009, 2011, 2012 J. Ali Harlow <ali@juiblex.co.uk>
+ * Copyright (C) 2009, 2011, 2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
return concat;
}
+/**
+ * razor_path_add_root:
+ *
+ * Adds a root to a path. path must be an absolute pathname. In POSIX
+ * environments this is equivalent to the concationation of root and path.
+ * In Microsoft Windows an adjustment may need to be made for a drive letter
+ * in path (which will be dropped).
+ *
+ * Returns: The new pathname.
+ **/
+RAZOR_EXPORT char *razor_path_add_root(const char *path, const char *root)
+{
+ if (root && *root)
+ return razor_concat(root, SKIP_DRIVE_LETTER(path), NULL);
+ else
+ return strdup(path);
+}
+
RAZOR_EXPORT const char *razor_system_arch(void)
{
#ifdef MSWIN_API