summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/path.c21
-rw-r--r--trust/save.c22
-rw-r--r--trust/token.c10
3 files changed, 37 insertions, 16 deletions
diff --git a/common/path.c b/common/path.c
index 89d9a67..818befc 100644
--- a/common/path.c
+++ b/common/path.c
@@ -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);
diff --git a/trust/save.c b/trust/save.c
index acef483..0f047fc 100644
--- a/trust/save.c
+++ b/trust/save.c
@@ -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);
diff --git a/trust/token.c b/trust/token.c
index c91acd2..12e9e4c 100644
--- a/trust/token.c
+++ b/trust/token.c
@@ -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;
}
}