1.1 --- a/rpm.c Wed Mar 12 16:40:50 2008 -0400
1.2 +++ b/rpm.c Tue Mar 18 11:44:28 2008 -0400
1.3 @@ -1,6 +1,7 @@
1.4 #include <stdio.h>
1.5 #include <stddef.h>
1.6 #include <string.h>
1.7 +#include <errno.h>
1.8 #include <sys/stat.h>
1.9 #include <sys/mman.h>
1.10 #include <sys/types.h>
1.11 @@ -265,16 +266,20 @@
1.12 const char *path, const char *name, unsigned int mode)
1.13 {
1.14 char buffer[PATH_MAX];
1.15 - int fd;
1.16 + struct stat buf;
1.17 + int fd, ret;
1.18
1.19 if (razor_create_dir(installer->root, path) < 0)
1.20 return -1;
1.21
1.22 - snprintf(buffer, sizeof buffer, "%s%s/%s",
1.23 + /* assertion: root doesn't end in a slash, path begins and end
1.24 + * with a slash, name does not begin with a slash. */
1.25 + snprintf(buffer, sizeof buffer, "%s%s%s",
1.26 installer->root, path, name);
1.27
1.28 switch (mode >> 12) {
1.29 case REG:
1.30 + /* FIXME: handle the case where a file is already there. */
1.31 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, mode & 0x1ff);
1.32 if (fd < 0){
1.33 fprintf(stderr, "failed to create file %s\n", buffer);
1.34 @@ -297,7 +302,16 @@
1.35 }
1.36 return 0;
1.37 case XDIR:
1.38 - return mkdir(buffer, mode & 0x1ff);
1.39 + ret = mkdir(buffer, mode & 0x1ff);
1.40 + if (ret == 0 || errno != EEXIST)
1.41 + return ret;
1.42 + if (stat(buffer, &buf) || !S_ISDIR(buf.st_mode)) {
1.43 + /* FIXME: also check that mode match. */
1.44 + fprintf(stderr,
1.45 + "%s exists but is not a directory\n", buffer);
1.46 + return -1;
1.47 + }
1.48 + return 0;
1.49 case PIPE:
1.50 case CDEV:
1.51 case BDEV: