diff -r 0a5e583393e1 -r bae5adee8c8c librazor/atomic-emulate.c --- a/librazor/atomic-emulate.c Tue Sep 09 15:27:12 2014 +0100 +++ b/librazor/atomic-emulate.c Fri Oct 17 09:57:19 2014 +0100 @@ -240,7 +240,7 @@ * unwritable directory and take one step back. */ char *s, *abspath, saved; - int len; + int len, can_step_back = 0; abspath = absolute_path(path); if (!abspath) { @@ -249,11 +249,15 @@ } if (stat(abspath, &buf) < 0) { - atomic->error = razor_error_new_posix(abspath); - free(abspath); - return -1; - } - filesystem = buf.st_dev; + if (errno == ENOENT) + filesystem = 0; + else { + atomic->error = razor_error_new_posix(abspath); + free(abspath); + return -1; + } + } else + filesystem = buf.st_dev; len = strlen(abspath); while(len > 1 && (s = strrchr(abspath, '/'))) { @@ -267,19 +271,27 @@ } if (stat(abspath, &buf) < 0) { - atomic->error = razor_error_new_posix(abspath); - free(abspath); - return -1; - } + if (errno == ENOENT) + continue; + else { + atomic->error = razor_error_new_posix(abspath); + free(abspath); + return -1; + } + } else if (!filesystem) + filesystem = buf.st_dev; if (buf.st_dev != filesystem || access(abspath, W_OK)) { - if (s == abspath) - s[1] = saved; - else - s[0] = '/'; + if (can_step_back) { + if (s == abspath) + s[1] = saved; + else + s[0] = '/'; + } len = strlen(abspath); break; - } + } else + can_step_back = 1; } if (len == 1)