Merge branch 'master' of git://people.freedesktop.org/~krh/razor
authorDan Winship <danw@gnome.org>
Thu Mar 13 08:29:05 2008 -0400 (2008-03-13)
changeset 1781efd1945b81a
parent 174 ac1387f6aba4
parent 176 1f7ea90fb2c1
child 179 a6dfb81e3484
Merge branch 'master' of git://people.freedesktop.org/~krh/razor
rpm.c
     1.1 --- a/Makefile	Wed Mar 12 16:41:34 2008 -0400
     1.2 +++ b/Makefile	Thu Mar 13 08:29:05 2008 -0400
     1.3 @@ -13,5 +13,9 @@
     1.4  test : test-driver
     1.5  	./test-driver test.xml
     1.6  
     1.7 +reset : ./razor
     1.8 +	rm -rf install
     1.9 +	./razor init
    1.10 +
    1.11  clean :
    1.12  	rm -f *.o razor
     2.1 --- a/main.c	Wed Mar 12 16:41:34 2008 -0400
     2.2 +++ b/main.c	Thu Mar 13 08:29:05 2008 -0400
     2.3 @@ -494,7 +494,7 @@
     2.4  	pi = razor_package_iterator_create(set);
     2.5  	i = 0;
     2.6  	while (razor_package_iterator_next(pi, &package, &name, &version))
     2.7 -		packages[i] = strdup(name);
     2.8 +		packages[i++] = strdup(name);
     2.9  	razor_package_iterator_destroy(pi);
    2.10  
    2.11  	return packages;
     3.1 --- a/rpm.c	Wed Mar 12 16:41:34 2008 -0400
     3.2 +++ b/rpm.c	Thu Mar 13 08:29:05 2008 -0400
     3.3 @@ -1,6 +1,7 @@
     3.4  #include <stdio.h>
     3.5  #include <stddef.h>
     3.6  #include <string.h>
     3.7 +#include <errno.h>
     3.8  #include <sys/stat.h>
     3.9  #include <sys/mman.h>
    3.10  #include <sys/types.h>
    3.11 @@ -265,16 +266,20 @@
    3.12  	    const char *path, const char *name, unsigned int mode)
    3.13  {
    3.14  	char buffer[PATH_MAX];
    3.15 -	int fd;
    3.16 +	struct stat buf;
    3.17 +	int fd, ret;
    3.18  
    3.19  	if (razor_create_dir(installer->root, path) < 0)
    3.20  		return -1;
    3.21  
    3.22 -	snprintf(buffer, sizeof buffer, "%s%s/%s",
    3.23 +	/* assertion: root doesn't end in a slash, path begins and end
    3.24 +	 * with a slash, name does not begin with a slash. */
    3.25 +	snprintf(buffer, sizeof buffer, "%s%s%s",
    3.26  		 installer->root, path, name);
    3.27  
    3.28  	switch (mode >> 12) {
    3.29  	case REG:
    3.30 +		/* FIXME: handle the case where a file is already there. */
    3.31  		fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, mode & 0x1ff);
    3.32  		if (fd < 0){
    3.33  			fprintf(stderr, "failed to create file %s\n", buffer);
    3.34 @@ -297,7 +302,16 @@
    3.35  		}
    3.36  		return 0;
    3.37  	case XDIR:
    3.38 -		return mkdir(buffer, mode & 0x1ff);
    3.39 +		ret = mkdir(buffer, mode & 0x1ff);
    3.40 +		if (ret == 0 || errno != EEXIST)
    3.41 +			return ret;
    3.42 +		if (stat(buffer, &buf) || !S_ISDIR(buf.st_mode)) {
    3.43 +			/* FIXME: also check that mode match. */
    3.44 +			fprintf(stderr,
    3.45 +				"%s exists but is not a directory\n", buffer);
    3.46 +			return -1;
    3.47 +		}
    3.48 +		return 0;
    3.49  	case PIPE:
    3.50  	case CDEV:
    3.51  	case BDEV: