Port razor_package_remove() to URI-based API
authorJ. Ali Harlow <ali@juiblex.co.uk>
Thu Jul 07 15:17:29 2016 +0100 (2016-07-07)
changeset 4794204db81cdbc
parent 478 8e4bf84a7bb8
child 480 18c1225cfa1b
Port razor_package_remove() to URI-based API
librazor/path.c
librazor/razor.c
librazor/razor.h.in
librazor/rpm.c
librazor/uri-io.c
     1.1 --- a/librazor/path.c	Thu Jul 07 11:04:10 2016 +0100
     1.2 +++ b/librazor/path.c	Thu Jul 07 15:17:29 2016 +0100
     1.3 @@ -171,7 +171,8 @@
     1.4  	/*
     1.5  	 * Under MS-Windows, c:/xxx maps to a path of /c:/xxx
     1.6  	 */
     1.7 -	if (is_alpha(path[0]) && path[1] == ':' && path[2] == '/')
     1.8 +	if (is_alpha(path[0]) && path[1] == ':' &&
     1.9 +	    (path[2] == '/' || path[2] == '\\'))
    1.10  		*p++ = '/';
    1.11  #endif
    1.12  
     2.1 --- a/librazor/razor.c	Thu Jul 07 11:04:10 2016 +0100
     2.2 +++ b/librazor/razor.c	Thu Jul 07 15:17:29 2016 +0100
     2.3 @@ -621,13 +621,13 @@
     2.4  RAZOR_EXPORT int
     2.5  razor_package_remove(struct razor_set *prev, struct razor_set *next,
     2.6  		     struct razor_atomic *atomic, struct razor_package *package,
     2.7 -		     const char *root, int install_count,
     2.8 +		     const char *root_uri, int install_count,
     2.9  		     enum razor_stage_type stage)
    2.10  {
    2.11  	struct razor_file_iterator *fi;
    2.12  	struct razor_package_iterator *pi;
    2.13  	struct razor_package *p;
    2.14 -	char *buffer, buf[32];
    2.15 +	char *uri, *relative, *buffer, buf[32];
    2.16  	const char *name, *program, *script;
    2.17  	int i, count, retval = 0;
    2.18  	struct environment env;
    2.19 @@ -655,8 +655,9 @@
    2.20  					  RAZOR_DETAIL_PREUN, &script,
    2.21  					  RAZOR_DETAIL_LAST);
    2.22  
    2.23 -		retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program,
    2.24 -					  script, install_count, &tmp_error);
    2.25 +		retval = razor_run_script(root_uri, RAZOR_PROPERTY_PREUN,
    2.26 +					  program, script, install_count,
    2.27 +					  &tmp_error);
    2.28  
    2.29  		if (retval < 0) {
    2.30  			razor_atomic_propagate_error(atomic, tmp_error, NULL);
    2.31 @@ -675,9 +676,34 @@
    2.32  				count++;
    2.33  			razor_package_iterator_destroy(pi);
    2.34  			if (count <= 0) {
    2.35 -				buffer = razor_concat(root, name, NULL);
    2.36 -				razor_atomic_remove(atomic, buffer);
    2.37 -				free(buffer);
    2.38 +				uri = razor_path_to_uri(name);
    2.39 +
    2.40 +				if (str_has_prefix(uri, "file:///"))
    2.41 +					relative = uri + 8;
    2.42 +				else if (str_has_prefix(uri, "file:/"))
    2.43 +					relative = uri + 6;
    2.44 +				else if (str_has_prefix(uri, "file:"))
    2.45 +					relative = uri + 5;
    2.46 +				else if (str_has_prefix(uri, "/"))
    2.47 +					relative = uri + 1;
    2.48 +				else
    2.49 +					relative = uri;
    2.50 +
    2.51 +				buffer = razor_resolve_uri_root(root_uri,
    2.52 +								relative, 1,
    2.53 +								&tmp_error);
    2.54 +				free(uri);
    2.55 +
    2.56 +				if (buffer) {
    2.57 +					razor_atomic_remove(atomic, buffer);
    2.58 +					free(buffer);
    2.59 +				} else {
    2.60 +					razor_atomic_propagate_error(atomic,
    2.61 +								     tmp_error,
    2.62 +								     NULL);
    2.63 +					tmp_error = NULL;
    2.64 +					break;
    2.65 +				}
    2.66  			}
    2.67  		}
    2.68  
    2.69 @@ -692,8 +718,9 @@
    2.70  					  RAZOR_DETAIL_POSTUN, &script,
    2.71  					  RAZOR_DETAIL_LAST);
    2.72  
    2.73 -		retval |= razor_run_script(root, RAZOR_PROPERTY_POSTUN, program,
    2.74 -					   script, install_count, &tmp_error);
    2.75 +		retval |= razor_run_script(root_uri, RAZOR_PROPERTY_POSTUN,
    2.76 +					   program, script, install_count,
    2.77 +					   &tmp_error);
    2.78  
    2.79  		if (retval < 0) {
    2.80  			razor_atomic_propagate_error(atomic, tmp_error, NULL);
     3.1 --- a/librazor/razor.h.in	Thu Jul 07 11:04:10 2016 +0100
     3.2 +++ b/librazor/razor.h.in	Thu Jul 07 15:17:29 2016 +0100
     3.3 @@ -192,11 +192,11 @@
     3.4  /**
     3.5   * razor_atomic_make_dirs
     3.6   * 
     3.7 - * Create all sub-directories leading up to path. We know root exists
     3.8 - * and is a dir, root does not end in a '/', and path either has a
     3.9 - * leading '/' or (on MS-Windows only) root is the empty string
    3.10 - * and path starts with drive (eg., "c:/windows").
    3.11 - * Note: path itself is not created, only the directory in which it
    3.12 + * Create all sub-directories leading up to uri. We know root_uri exists
    3.13 + * and is a dir, root_uri does not end in a '/', and uri either has a
    3.14 + * leading '/' or (on MS-Windows only) root_uri is the empty string
    3.15 + * and uri starts with drive (eg., "c:/windows").
    3.16 + * Note: uri itself is not created, only the directory in which it
    3.17   * (would) exist.
    3.18   *
    3.19   * Returns: non-zero on error.
    3.20 @@ -301,7 +301,7 @@
    3.21  int
    3.22  razor_package_remove(struct razor_set *prev, struct razor_set *next,
    3.23  		     struct razor_atomic *atomic, struct razor_package *package,
    3.24 -		     const char *root, int install_count,
    3.25 +		     const char *root_uri, int install_count,
    3.26  		     enum razor_stage_type stage);
    3.27  
    3.28  /**
     4.1 --- a/librazor/rpm.c	Thu Jul 07 11:04:10 2016 +0100
     4.2 +++ b/librazor/rpm.c	Thu Jul 07 15:17:29 2016 +0100
     4.3 @@ -1087,7 +1087,7 @@
     4.4  }
     4.5  
     4.6  int
     4.7 -razor_run_script(const char *root, enum razor_property_flags script,
     4.8 +razor_run_script(const char *root_uri, enum razor_property_flags script,
     4.9  		 const char *program, const char *body, int arg1,
    4.10  		 struct razor_error **error)
    4.11  {
    4.12 @@ -1120,10 +1120,11 @@
    4.13  			script_tag = 0;
    4.14  			break;
    4.15  		}
    4.16 -		retval = run_script_lua(root, script_tag, body, arg1, error);
    4.17 +		retval = run_script_lua(root_uri, script_tag, body, arg1, error);
    4.18  	}
    4.19  	else
    4.20 -		retval = run_script_external(root, program, body, arg1, error);
    4.21 +		retval = run_script_external(root_uri, program, body, arg1,
    4.22 +					     error);
    4.23  
    4.24  	return retval;
    4.25  }
     5.1 --- a/librazor/uri-io.c	Thu Jul 07 11:04:10 2016 +0100
     5.2 +++ b/librazor/uri-io.c	Thu Jul 07 15:17:29 2016 +0100
     5.3 @@ -1143,8 +1143,11 @@
     5.4  	if (path) {
     5.5  		razor_uri_destroy(&ru);
     5.6  		s = razor_file_mkdtemp_near(path, template, error);
     5.7 -		retval = razor_path_to_uri(s);
     5.8 -		free(s);
     5.9 +		if (s) {
    5.10 +			retval = razor_path_to_uri(s);
    5.11 +			free(s);
    5.12 +		} else
    5.13 +			retval = NULL;
    5.14  		free(path);
    5.15  	} else {
    5.16  		entry = razor_uri_get_vtable_entry(ru.scheme);