From: J. Ali Harlow Date: Sat, 23 Aug 2014 15:07:09 +0000 (+0100) Subject: Drop drive letter from path to razor root when RAZOR_ROOT set. X-Git-Tag: 0.6~22 X-Git-Url: http://project.juiblex.co.uk/git/?a=commitdiff_plain;h=5bbdaf077007db6714e8476d58d5ed507e03470c;p=razor.git Drop drive letter from path to razor root when RAZOR_ROOT set. If the RAZOR_ROOT environment variable was set to eg., /root then on Microsoft Windows we were trying to use paths such as /rootC:/Programs which is obviously wrong. Instead we should drop the drive letter giving paths of the form /root/Programs. Note that the drive letter is _not_ migrated to C:/root/Programs: If a root of C:/root was desired then RAZOR_ROOT would have been set to C:/root. --- diff --git a/librazor/atomic-ktm.c b/librazor/atomic-ktm.c index 3bf6dc6..475dcb3 100644 --- a/librazor/atomic-ktm.c +++ b/librazor/atomic-ktm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 J. Ali Harlow + * Copyright (C) 2011, 2012, 2014 J. Ali Harlow * * 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 @@ -36,9 +36,6 @@ #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) { @@ -187,7 +184,7 @@ razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root, 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, "/\\"); diff --git a/librazor/atomic-none.c b/librazor/atomic-none.c index c06b7c7..c7bf99d 100644 --- a/librazor/atomic-none.c +++ b/librazor/atomic-none.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 J. Ali Harlow + * Copyright (C) 2011, 2012, 2014 J. Ali Harlow * * 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 @@ -78,7 +78,8 @@ razor_atomic_make_dirs(struct razor_atomic *atomic, const char *root, strcpy(buffer, root); p = buffer + strlen(buffer); - slash = path; + slash = (p > buffer) ? SKIP_DRIVE_PATH(path) : path; + for (slash = path; *slash != '\0'; slash = next) { #ifdef MSWIN_API next = strpbrk(slash + 1, "/\\"); diff --git a/librazor/razor-internal.h b/librazor/razor-internal.h index 05204ec..55ad9cb 100644 --- a/librazor/razor-internal.h +++ b/librazor/razor-internal.h @@ -346,4 +346,15 @@ struct razor_atomic { int razor_allow_all_root_names(void); int razor_valid_root_name(const char *name); +#define RAZOR_ASCII_ISALPHA(c) \ + ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z') + +#ifdef MSWIN_API +#define SKIP_DRIVE_LETTER(path) \ + ((RAZOR_ASCII_ISALPHA(path[0]) && (path)[1] == ':') ? \ + (path) + 2 : (path)) +#else +#define SKIP_DRIVE_LETTER(path) (path) +#endif /* MSWIN_API */ + #endif /* _RAZOR_INTERNAL_H_ */ diff --git a/librazor/razor.h b/librazor/razor.h index 3277d03..55bbe63 100644 --- a/librazor/razor.h +++ b/librazor/razor.h @@ -590,6 +590,8 @@ void (*razor_get_lua_loader(const char *modname))(); char *razor_concat(const char *s, ...) RAZOR_MALLOC RAZOR_NULL_TERMINATED; +char *razor_path_add_root(const char *path, const char *root) RAZOR_MALLOC; + const char *razor_system_arch(void); #endif /* _RAZOR_H_ */ diff --git a/librazor/root.c b/librazor/root.c index 4ec5e49..7db364a 100644 --- a/librazor/root.c +++ b/librazor/root.c @@ -102,7 +102,7 @@ razor_root_create(const char *root, struct razor_error **error) } 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, @@ -133,7 +133,7 @@ RAZOR_EXPORT struct razor_root * 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); @@ -152,8 +152,9 @@ razor_root_open(const char *root, struct razor_error **error) 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); @@ -167,8 +168,9 @@ razor_root_open(const char *root, struct razor_error **error) 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)) { @@ -184,7 +186,7 @@ razor_root_open(const char *root, struct razor_error **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); @@ -196,8 +198,10 @@ razor_root_open_read_only(const char *root, struct razor_error **error) 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"); @@ -207,8 +211,10 @@ razor_root_open_read_only(const char *root, struct razor_error **error) } 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); diff --git a/librazor/util.c b/librazor/util.c index 5ede1a1..026b640 100644 --- a/librazor/util.c +++ b/librazor/util.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc - * Copyright (C) 2009, 2011, 2012 J. Ali Harlow + * Copyright (C) 2009, 2011, 2012, 2014 J. Ali Harlow * * 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 @@ -341,6 +341,24 @@ RAZOR_EXPORT char *razor_concat(const char *s, ...) 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