1.1 --- a/librazor/atomic-actions.c Sat Aug 23 17:24:34 2014 +0100
1.2 +++ b/librazor/atomic-actions.c Mon Sep 01 12:19:32 2014 +0100
1.3 @@ -489,7 +489,7 @@
1.4 if (razor_atomic_in_error_state(atomic)) {
1.5 atomic_action_undo(atomic, done);
1.6 done = NULL;
1.7 - atomic_action_free(actions);
1.8 + atomic_action_free(a);
1.9 }
1.10 }
1.11
2.1 --- a/librazor/atomic-emulate.c Sat Aug 23 17:24:34 2014 +0100
2.2 +++ b/librazor/atomic-emulate.c Mon Sep 01 12:19:32 2014 +0100
2.3 @@ -1,5 +1,5 @@
2.4 /*
2.5 - * Copyright (C) 2012 J. Ali Harlow <ali@juiblex.co.uk>
2.6 + * Copyright (C) 2012, 2014 J. Ali Harlow <ali@juiblex.co.uk>
2.7 *
2.8 * This program is free software; you can redistribute it and/or modify
2.9 * it under the terms of the GNU General Public License as published by
2.10 @@ -29,6 +29,7 @@
2.11 #include <fcntl.h>
2.12 #include <dirent.h>
2.13 #include <errno.h>
2.14 +#include <unistd.h>
2.15 #include "razor-internal.h"
2.16
2.17 /*
2.18 @@ -119,21 +120,70 @@
2.19 free(atomic);
2.20 }
2.21
2.22 +#ifndef MSWIN_API
2.23 +static char *absolute_path(const char *path)
2.24 +{
2.25 + int len;
2.26 + char *result, *subpath, *p, *s, *t;
2.27 +
2.28 + result = realpath(path, NULL);
2.29 +
2.30 + if (!result && errno == ENOENT) {
2.31 + p = strdup(path);
2.32 + s = strrchr(p, '/');
2.33 +
2.34 + while (s) {
2.35 + if (s == p) {
2.36 + result = strdup("/");
2.37 + break;
2.38 + }
2.39 +
2.40 + *s = '\0';
2.41 + subpath = realpath(p, NULL);
2.42 +
2.43 + if (subpath) {
2.44 + *s = '/';
2.45 + len = strlen(subpath);
2.46 + result = malloc(len + strlen(s) + 1);
2.47 + memcpy(result, subpath, len);
2.48 + strcpy(result + len, s);
2.49 + break;
2.50 + } else if (errno != ENOENT)
2.51 + break;
2.52 +
2.53 + t = strrchr(p, '/');
2.54 + *s = '/';
2.55 + s = t;
2.56 + }
2.57 +
2.58 + if (!s)
2.59 + result = realpath(".", NULL);
2.60 +
2.61 + free(p);
2.62 + }
2.63 +
2.64 + return result;
2.65 +}
2.66 +#endif
2.67 +
2.68 /*
2.69 * We need a toplevel directory in which to hold temporary files
2.70 * before they are committed. Since we can generally assume that
2.71 - * we have write permissions anywhere on the disk in question,
2.72 - * the best location is in the relevant root directory. The most
2.73 - * common case where this assumption fails is when testing, when
2.74 - * the current directory is a good choice.
2.75 - * It might be even better to find a mount point above path instead
2.76 - * but this is hard to do, and probably not worth the effort.
2.77 + * we have write permissions anywhere on the filesystem in
2.78 + * question, the best location is at the relevant mount point.
2.79 + * The most common case where this assumption fails is when
2.80 + * testing, when the current directory is a good choice.
2.81 */
2.82
2.83 static int
2.84 razor_atomic_set_toplevel_from_path(struct razor_atomic *atomic,
2.85 const char *path)
2.86 {
2.87 +#ifndef MSWIN_API
2.88 + dev_t filesystem;
2.89 + struct stat buf;
2.90 +#endif
2.91 +
2.92 if (razor_atomic_in_error_state(atomic))
2.93 return -1;
2.94
2.95 @@ -183,7 +233,66 @@
2.96 free(buf);
2.97 }
2.98 #else
2.99 - atomic->toplevel = strdup("/.atomic-XXXXXX");
2.100 + {
2.101 + /*
2.102 + * Find the mount point (assuming we can write to the
2.103 + * whole filesystem). Otherwise stop at the first
2.104 + * unwritable directory and take one step back.
2.105 + */
2.106 + char *s, *abspath, saved;
2.107 + int len;
2.108 +
2.109 + abspath = absolute_path(path);
2.110 + if (!abspath) {
2.111 + atomic->error = razor_error_new_str(path,
2.112 + strerror(errno));
2.113 + return -1;
2.114 + }
2.115 +
2.116 + if (stat(abspath, &buf) < 0) {
2.117 + atomic->error = razor_error_new_str(abspath,
2.118 + strerror(errno));
2.119 + free(abspath);
2.120 + return -1;
2.121 + }
2.122 + filesystem = buf.st_dev;
2.123 +
2.124 + len = strlen(abspath);
2.125 + while(len > 1 && (s = strrchr(abspath, '/'))) {
2.126 + if (s == abspath) {
2.127 + saved = s[1];
2.128 + s[1] = '\0';
2.129 + len = s + 1 - abspath;
2.130 + } else {
2.131 + s[0] = '\0';
2.132 + len = s - abspath;
2.133 + }
2.134 +
2.135 + if (stat(abspath, &buf) < 0) {
2.136 + atomic->error =
2.137 + razor_error_new_str(abspath, strerror(errno));
2.138 + free(abspath);
2.139 + return -1;
2.140 + }
2.141 +
2.142 + if (buf.st_dev != filesystem || access(abspath, W_OK)) {
2.143 + if (s == abspath)
2.144 + s[1] = saved;
2.145 + else
2.146 + s[0] = '/';
2.147 + len = strlen(abspath);
2.148 + break;
2.149 + }
2.150 + }
2.151 +
2.152 + if (len == 1)
2.153 + len = 0; /* Avoid an unslightly double slash. */
2.154 + atomic->toplevel = malloc(len + strlen("/.atomic-XXXXXX") + 1);
2.155 + memcpy(atomic->toplevel, abspath, len);
2.156 + strcpy(atomic->toplevel + len, "/.atomic-XXXXXX");
2.157 +
2.158 + free(abspath);
2.159 + }
2.160 #endif
2.161
2.162 if (!mkdtemp(atomic->toplevel)) {
2.163 @@ -193,6 +302,24 @@
2.164 if (err == EACCES) {
2.165 char *s = strdup("atomic-XXXXXX");
2.166
2.167 +#ifndef MSWIN_API
2.168 + if (stat(".", &buf) < 0) {
2.169 + atomic->error =
2.170 + razor_error_new_str(".", strerror(errno));
2.171 + free(s);
2.172 + free(atomic->toplevel);
2.173 + atomic->toplevel = NULL;
2.174 + return -1;
2.175 + }
2.176 + if (buf.st_dev != filesystem)
2.177 + /*
2.178 + * Don't use a different filesystem. It will
2.179 + * only fail later on (in rename) and cause
2.180 + * an unhelpful error message (EXDEV).
2.181 + */
2.182 + free(s);
2.183 + else
2.184 +#endif
2.185 if (mkdtemp(s)) {
2.186 free(atomic->toplevel);
2.187 atomic->toplevel = s;
3.1 --- a/po/POTFILES.in Sat Aug 23 17:24:34 2014 +0100
3.2 +++ b/po/POTFILES.in Mon Sep 01 12:19:32 2014 +0100
3.3 @@ -1,3 +1,1 @@
3.4 -gl/error.c
3.5 gl/fnmatch_loop.c
3.6 -gl/xalloc-die.c
4.1 --- a/src/test-driver.c Sat Aug 23 17:24:34 2014 +0100
4.2 +++ b/src/test-driver.c Mon Sep 01 12:19:32 2014 +0100
4.3 @@ -18,6 +18,7 @@
4.4 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4.5 */
4.6
4.7 +#include "config.h"
4.8 #include <stdio.h>
4.9 #include <string.h>
4.10 #include <stdarg.h>
5.1 --- a/test/Makefile.am Sat Aug 23 17:24:34 2014 +0100
5.2 +++ b/test/Makefile.am Mon Sep 01 12:19:32 2014 +0100
5.3 @@ -43,7 +43,7 @@
5.4 mkdir -p base/rpms
5.5 mv rpmbuild/RPMS/noarch/*.rpm base/rpms
5.6 rm -rf rpmbuild
5.7 - createrepo -o base base/rpms
5.8 + createrepo --simple-md-filenames -o base base/rpms
5.9
5.10 updates/repodata/primary.xml.gz: zip.spec Makefile
5.11 rm -rf rpmbuild updates
5.12 @@ -53,7 +53,7 @@
5.13 mkdir -p updates/rpms
5.14 mv rpmbuild/RPMS/noarch/*.rpm updates/rpms
5.15 rm -rf rpmbuild
5.16 - createrepo -o updates updates/rpms
5.17 + createrepo --simple-md-filenames -o updates updates/rpms
5.18
5.19 primary.xml.gz: base/repodata/primary.xml.gz
5.20 cp base/repodata/primary.xml.gz base/repodata/filelists.xml.gz .