librazor/razor.c
changeset 478 8e4bf84a7bb8
parent 462 94d7459828ba
child 479 4204db81cdbc
     1.1 --- a/librazor/razor.c	Thu Nov 13 10:44:53 2014 +0000
     1.2 +++ b/librazor/razor.c	Thu Jul 07 11:04:10 2016 +0100
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5   * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     1.6   * Copyright (C) 2008  Red Hat, Inc
     1.7 - * Copyright (C) 2009-2012  J. Ali Harlow <ali@juiblex.co.uk>
     1.8 + * Copyright (C) 2009-2012, 2016  J. Ali Harlow <ali@juiblex.co.uk>
     1.9   *
    1.10   * This program is free software; you can redistribute it and/or modify
    1.11   * it under the terms of the GNU General Public License as published by
    1.12 @@ -28,10 +28,8 @@
    1.13  #include <stdio.h>
    1.14  #include <stdarg.h>
    1.15  #include <string.h>
    1.16 -#include <sys/types.h>
    1.17 -#include <sys/stat.h>
    1.18 +#include <fcntl.h>
    1.19  #include <unistd.h>
    1.20 -#include <fcntl.h>
    1.21  #include <errno.h>
    1.22  #include <ctype.h>
    1.23  #include <fnmatch.h>
    1.24 @@ -140,7 +138,7 @@
    1.25  };
    1.26  
    1.27  RAZOR_EXPORT int
    1.28 -razor_set_bind_sections(struct razor_set *set, const char *filename,
    1.29 +razor_set_bind_sections(struct razor_set *set, const char *uri,
    1.30  			enum razor_set_flags flags, struct razor_error **error)
    1.31  {
    1.32  	struct razor_set_section *s, *sections;
    1.33 @@ -156,9 +154,9 @@
    1.34  		return -1;
    1.35  	}
    1.36  
    1.37 -	file->header = razor_file_get_contents(filename, &file->size,
    1.38 -					       flags & RAZOR_SET_PRIVATE,
    1.39 -					       error);
    1.40 +	file->header = razor_uri_get_contents(uri, &file->size,
    1.41 +					      flags & RAZOR_SET_PRIVATE,
    1.42 +					      error);
    1.43  	if (!file->header) {
    1.44  		free(file);
    1.45  		return -1;
    1.46 @@ -178,9 +176,8 @@
    1.47  		reason = NULL;
    1.48  
    1.49  	if (reason) {
    1.50 -		razor_set_error(error, RAZOR_GENERAL_ERROR, code, filename,
    1.51 -				reason);
    1.52 -		razor_file_free_contents(file->header, file->size);
    1.53 +		razor_set_error(error, RAZOR_GENERAL_ERROR, code, uri, reason);
    1.54 +		razor_uri_free_contents(file->header, file->size);
    1.55  		free(file);
    1.56  		return -1;
    1.57  	}
    1.58 @@ -220,7 +217,7 @@
    1.59  }
    1.60  
    1.61  RAZOR_EXPORT struct razor_set *
    1.62 -razor_set_open(const char *filename, enum razor_set_flags flags,
    1.63 +razor_set_open(const char *uri, enum razor_set_flags flags,
    1.64  	       struct razor_error **error)
    1.65  {
    1.66  	struct razor_set *set;
    1.67 @@ -234,7 +231,7 @@
    1.68  
    1.69  	set->lock_fd = -1;
    1.70  	set->ref_count = 1;
    1.71 -	if (razor_set_bind_sections(set, filename, flags, error)) {
    1.72 +	if (razor_set_bind_sections(set, uri, flags, error)) {
    1.73  		free(set);
    1.74  		return NULL;
    1.75  	}
    1.76 @@ -242,18 +239,18 @@
    1.77  }
    1.78  
    1.79  int
    1.80 -razor_set_aquire_lock(struct razor_set *set, const char *path, int exclusive)
    1.81 +razor_set_acquire_lock(struct razor_set *set, const char *uri, int exclusive)
    1.82  {
    1.83  	int fd;
    1.84  	assert(set != NULL);
    1.85  
    1.86 -	if (path) {
    1.87 -		fd = open(path, O_CREAT | O_RDWR | O_TRUNC | O_BINARY, 0666);
    1.88 +	if (uri) {
    1.89 +		fd = razor_uri_open(uri, O_CREAT | O_RDWR | O_TRUNC | O_BINARY,
    1.90 +				    0666, NULL);
    1.91  		if (fd < 0)
    1.92  			return -1;
    1.93 -	} else {
    1.94 +	} else
    1.95  		fd = -1;
    1.96 -	}
    1.97  
    1.98  #ifdef MSWIN_API
    1.99  	DWORD flags = LOCKFILE_FAIL_IMMEDIATELY;
   1.100 @@ -310,12 +307,12 @@
   1.101  	} else {
   1.102  		for (file = set->mapped_files; file != NULL; file = next) {
   1.103  			next = file->next;
   1.104 -			razor_file_free_contents(file->header, file->size);
   1.105 +			razor_uri_free_contents(file->header, file->size);
   1.106  			free(file);
   1.107  		}
   1.108  	}
   1.109  
   1.110 -	razor_set_aquire_lock(set, NULL, 0);
   1.111 +	razor_set_acquire_lock(set, NULL, 0);
   1.112  	free(set);
   1.113  }
   1.114  
   1.115 @@ -390,11 +387,11 @@
   1.116  
   1.117  RAZOR_EXPORT int
   1.118  razor_set_write(struct razor_set *set, struct razor_atomic *atomic,
   1.119 -		const char *filename, uint32_t sections)
   1.120 +		const char *uri, uint32_t sections)
   1.121  {
   1.122  	int h;
   1.123  
   1.124 -	h = razor_atomic_create_file(atomic, filename,
   1.125 +	h = razor_atomic_create_file(atomic, uri,
   1.126  				     S_IRWXU | S_IRWXG | S_IRWXO);
   1.127  	if (h < 0)
   1.128  		return -1;
   1.129 @@ -636,6 +633,7 @@
   1.130  	struct environment env;
   1.131  	struct list *link;
   1.132  	const char *prefix;
   1.133 +	struct razor_error *tmp_error = NULL;
   1.134  
   1.135  	if (stage & RAZOR_STAGE_SCRIPTS) {
   1.136  		environment_init(&env);
   1.137 @@ -658,7 +656,12 @@
   1.138  					  RAZOR_DETAIL_LAST);
   1.139  
   1.140  		retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program,
   1.141 -					  script, install_count);
   1.142 +					  script, install_count, &tmp_error);
   1.143 +
   1.144 +		if (retval < 0) {
   1.145 +			razor_atomic_propagate_error(atomic, tmp_error, NULL);
   1.146 +			tmp_error = NULL;
   1.147 +		}
   1.148  	}
   1.149  
   1.150  	if (!retval && (stage & RAZOR_STAGE_FILES)) {
   1.151 @@ -690,7 +693,12 @@
   1.152  					  RAZOR_DETAIL_LAST);
   1.153  
   1.154  		retval |= razor_run_script(root, RAZOR_PROPERTY_POSTUN, program,
   1.155 -					   script, install_count);
   1.156 +					   script, install_count, &tmp_error);
   1.157 +
   1.158 +		if (retval < 0) {
   1.159 +			razor_atomic_propagate_error(atomic, tmp_error, NULL);
   1.160 +			tmp_error = NULL;
   1.161 +		}
   1.162  	}
   1.163  
   1.164  	if (stage & RAZOR_STAGE_SCRIPTS) {