# HG changeset patch # User J. Ali Harlow # Date 1408806429 -3600 # Node ID cf499fd51df7543278e7fca74f96566aeadad603 # Parent 48204dea0b9f08a7486d9782827b82d4977b7b97 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 -r 48204dea0b9f -r cf499fd51df7 librazor/atomic-ktm.c --- a/librazor/atomic-ktm.c Sat Aug 23 11:13:48 2014 +0100 +++ b/librazor/atomic-ktm.c Sat Aug 23 16:07:09 2014 +0100 @@ -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 @@ 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 -r 48204dea0b9f -r cf499fd51df7 librazor/atomic-none.c --- a/librazor/atomic-none.c Sat Aug 23 11:13:48 2014 +0100 +++ b/librazor/atomic-none.c Sat Aug 23 16:07:09 2014 +0100 @@ -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 @@ 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 -r 48204dea0b9f -r cf499fd51df7 librazor/razor-internal.h --- a/librazor/razor-internal.h Sat Aug 23 11:13:48 2014 +0100 +++ b/librazor/razor-internal.h Sat Aug 23 16:07:09 2014 +0100 @@ -346,4 +346,15 @@ 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 -r 48204dea0b9f -r cf499fd51df7 librazor/razor.h --- a/librazor/razor.h Sat Aug 23 11:13:48 2014 +0100 +++ b/librazor/razor.h Sat Aug 23 16:07:09 2014 +0100 @@ -590,6 +590,8 @@ 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 -r 48204dea0b9f -r cf499fd51df7 librazor/root.c --- a/librazor/root.c Sat Aug 23 11:13:48 2014 +0100 +++ b/librazor/root.c Sat Aug 23 16:07:09 2014 +0100 @@ -102,7 +102,7 @@ } 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_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 @@ 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 @@ 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_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 @@ 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 @@ } 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 -r 48204dea0b9f -r cf499fd51df7 librazor/util.c --- a/librazor/util.c Sat Aug 23 11:13:48 2014 +0100 +++ b/librazor/util.c Sat Aug 23 16:07:09 2014 +0100 @@ -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 @@ 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