# HG changeset patch # User J. Ali Harlow # Date 1467901049 -3600 # Node ID 4204db81cdbc043f463f3a88ba8f1cb3f94b8631 # Parent 8e4bf84a7bb88098e8b84e1b811cf46a78760f79 Port razor_package_remove() to URI-based API diff -r 8e4bf84a7bb8 -r 4204db81cdbc librazor/path.c --- a/librazor/path.c Thu Jul 07 11:04:10 2016 +0100 +++ b/librazor/path.c Thu Jul 07 15:17:29 2016 +0100 @@ -171,7 +171,8 @@ /* * Under MS-Windows, c:/xxx maps to a path of /c:/xxx */ - if (is_alpha(path[0]) && path[1] == ':' && path[2] == '/') + if (is_alpha(path[0]) && path[1] == ':' && + (path[2] == '/' || path[2] == '\\')) *p++ = '/'; #endif diff -r 8e4bf84a7bb8 -r 4204db81cdbc librazor/razor.c --- a/librazor/razor.c Thu Jul 07 11:04:10 2016 +0100 +++ b/librazor/razor.c Thu Jul 07 15:17:29 2016 +0100 @@ -621,13 +621,13 @@ RAZOR_EXPORT int razor_package_remove(struct razor_set *prev, struct razor_set *next, struct razor_atomic *atomic, struct razor_package *package, - const char *root, int install_count, + const char *root_uri, int install_count, enum razor_stage_type stage) { struct razor_file_iterator *fi; struct razor_package_iterator *pi; struct razor_package *p; - char *buffer, buf[32]; + char *uri, *relative, *buffer, buf[32]; const char *name, *program, *script; int i, count, retval = 0; struct environment env; @@ -655,8 +655,9 @@ RAZOR_DETAIL_PREUN, &script, RAZOR_DETAIL_LAST); - retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program, - script, install_count, &tmp_error); + retval = razor_run_script(root_uri, RAZOR_PROPERTY_PREUN, + program, script, install_count, + &tmp_error); if (retval < 0) { razor_atomic_propagate_error(atomic, tmp_error, NULL); @@ -675,9 +676,34 @@ count++; razor_package_iterator_destroy(pi); if (count <= 0) { - buffer = razor_concat(root, name, NULL); - razor_atomic_remove(atomic, buffer); - free(buffer); + uri = razor_path_to_uri(name); + + if (str_has_prefix(uri, "file:///")) + relative = uri + 8; + else if (str_has_prefix(uri, "file:/")) + relative = uri + 6; + else if (str_has_prefix(uri, "file:")) + relative = uri + 5; + else if (str_has_prefix(uri, "/")) + relative = uri + 1; + else + relative = uri; + + buffer = razor_resolve_uri_root(root_uri, + relative, 1, + &tmp_error); + free(uri); + + if (buffer) { + razor_atomic_remove(atomic, buffer); + free(buffer); + } else { + razor_atomic_propagate_error(atomic, + tmp_error, + NULL); + tmp_error = NULL; + break; + } } } @@ -692,8 +718,9 @@ RAZOR_DETAIL_POSTUN, &script, RAZOR_DETAIL_LAST); - retval |= razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, - script, install_count, &tmp_error); + retval |= razor_run_script(root_uri, RAZOR_PROPERTY_POSTUN, + program, script, install_count, + &tmp_error); if (retval < 0) { razor_atomic_propagate_error(atomic, tmp_error, NULL); diff -r 8e4bf84a7bb8 -r 4204db81cdbc librazor/razor.h.in --- a/librazor/razor.h.in Thu Jul 07 11:04:10 2016 +0100 +++ b/librazor/razor.h.in Thu Jul 07 15:17:29 2016 +0100 @@ -192,11 +192,11 @@ /** * razor_atomic_make_dirs * - * Create all sub-directories leading up to path. We know root exists - * and is a dir, root does not end in a '/', and path either has a - * leading '/' or (on MS-Windows only) root is the empty string - * and path starts with drive (eg., "c:/windows"). - * Note: path itself is not created, only the directory in which it + * Create all sub-directories leading up to uri. We know root_uri exists + * and is a dir, root_uri does not end in a '/', and uri either has a + * leading '/' or (on MS-Windows only) root_uri is the empty string + * and uri starts with drive (eg., "c:/windows"). + * Note: uri itself is not created, only the directory in which it * (would) exist. * * Returns: non-zero on error. @@ -301,7 +301,7 @@ int razor_package_remove(struct razor_set *prev, struct razor_set *next, struct razor_atomic *atomic, struct razor_package *package, - const char *root, int install_count, + const char *root_uri, int install_count, enum razor_stage_type stage); /** diff -r 8e4bf84a7bb8 -r 4204db81cdbc librazor/rpm.c --- a/librazor/rpm.c Thu Jul 07 11:04:10 2016 +0100 +++ b/librazor/rpm.c Thu Jul 07 15:17:29 2016 +0100 @@ -1087,7 +1087,7 @@ } int -razor_run_script(const char *root, enum razor_property_flags script, +razor_run_script(const char *root_uri, enum razor_property_flags script, const char *program, const char *body, int arg1, struct razor_error **error) { @@ -1120,10 +1120,11 @@ script_tag = 0; break; } - retval = run_script_lua(root, script_tag, body, arg1, error); + retval = run_script_lua(root_uri, script_tag, body, arg1, error); } else - retval = run_script_external(root, program, body, arg1, error); + retval = run_script_external(root_uri, program, body, arg1, + error); return retval; } diff -r 8e4bf84a7bb8 -r 4204db81cdbc librazor/uri-io.c --- a/librazor/uri-io.c Thu Jul 07 11:04:10 2016 +0100 +++ b/librazor/uri-io.c Thu Jul 07 15:17:29 2016 +0100 @@ -1143,8 +1143,11 @@ if (path) { razor_uri_destroy(&ru); s = razor_file_mkdtemp_near(path, template, error); - retval = razor_path_to_uri(s); - free(s); + if (s) { + retval = razor_path_to_uri(s); + free(s); + } else + retval = NULL; free(path); } else { entry = razor_uri_get_vtable_entry(ru.scheme);