]> granicus.if.org Git - p11-kit/commitdiff
Fixes for some recent win32 regressions
authorStef Walter <stef@thewalter.net>
Wed, 17 Jul 2013 13:53:33 +0000 (15:53 +0200)
committerStef Walter <stef@thewalter.net>
Thu, 18 Jul 2013 04:53:11 +0000 (06:53 +0200)
common/path.c
trust/save.c
trust/token.c

index 89d9a673fe769fb5484388822417df27791f2d06..818befcca65a5e17ed3f8857848630ca5dd30aea 100644 (file)
@@ -228,6 +228,7 @@ p11_path_build (const char *path,
        size_t len;
        size_t at;
        size_t num;
+       size_t until;
        va_list va;
 
        return_val_if_fail (path != NULL, NULL);
@@ -247,14 +248,28 @@ p11_path_build (const char *path,
        path = first;
        va_start (va, path);
        while (path != NULL) {
-               if (at != 0 && built[at - 1] != delim && path[0] != delim)
-                       built[at++] = delim;
                num = strlen (path);
+
+               /* Trim end of the path */
+               until = (at > 0) ? 0 : 1;
+               while (num > until && is_path_component_or_null (path[num - 1]))
+                       num--;
+
+               if (at != 0) {
+                       if (num == 0)
+                               continue;
+                       built[at++] = delim;
+               }
+
                assert (at + num < len);
                memcpy (built + at, path, num);
-
                at += num;
+
                path = va_arg (va, const char *);
+
+               /* Trim beginning of path */
+               while (path && path[0] && is_path_component_or_null (path[0]))
+                       path++;
        }
        va_end (va);
 
index acef483b46a75334b26e3f33345a6f0deaae64ea..0f047fcda2778ee9584408f8968d10a6d515478f 100644 (file)
@@ -282,20 +282,18 @@ p11_save_finish_file (p11_save_file *file,
                        if (!path)
                                ret = false;
 
-               } else {
-                       if ((file->flags & P11_SAVE_OVERWRITE) &&
+               } else if ((file->flags & P11_SAVE_OVERWRITE) &&
                            unlink (path) < 0 && errno != ENOENT) {
-                               p11_message ("couldn't remove original file: %s: %s",
-                                            path, strerror (errno));
-                               ret = false;
-                       }
+                       p11_message ("couldn't remove original file: %s: %s",
+                                    path, strerror (errno));
+                       ret = false;
+               }
 
-                       if (ret == true &&
-                           rename (file->temp, file->path) < 0) {
-                               p11_message ("couldn't complete writing file: %s: %s",
-                                            file->path, strerror (errno));
-                               ret = false;
-                       }
+               if (ret == true &&
+                   rename (file->temp, path) < 0) {
+                       p11_message ("couldn't complete writing file: %s: %s",
+                                    path, strerror (errno));
+                       ret = false;
                }
 
                unlink (file->temp);
index c91acd2b5411310ccee005948ffcfc47520d12a0..12e9e4c2879797a41f3949af1b9fa2595253beda 100644 (file)
@@ -572,11 +572,15 @@ writer_put_object (p11_save_file *file,
 static bool
 mkdir_with_parents (const char *path)
 {
-       int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
        char *parent;
        bool ret;
 
+#ifdef OS_UNIX
+       int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
        if (mkdir (path, mode) == 0)
+#else
+       if (mkdir (path) == 0)
+#endif
                return true;
 
        switch (errno) {
@@ -586,7 +590,11 @@ mkdir_with_parents (const char *path)
                        ret = mkdir_with_parents (parent);
                        free (parent);
                        if (ret == true) {
+#ifdef OS_UNIX
                                if (mkdir (path, mode) == 0)
+#else
+                               if (mkdir (path) == 0)
+#endif
                                        return true;
                        }
                }