static time_t startup_time; /* When we started the last validation */
-static int
-init_cache_pb(struct path_builder *pb, char const *subdir)
-{
- int error;
-
- pb_init(pb);
- error = pb_append(pb, config_get_local_repository());
- if (error)
- goto cancel;
- error = pb_append(pb, subdir);
- if (error)
- goto cancel;
-
- return 0;
-
-cancel:
- pb_cleanup(pb);
- return error;
-}
-
/* Minimizes multiple evaluation */
static struct cache_node *
add_child(struct cache_node *parent, char const *basename)
struct path_builder pb;
int error;
- error = init_cache_pb(&pb, "metadata.json");
- if (error) {
- pb_cleanup(&pb);
+ error = pb_init_cache(&pb, "metadata.json");
+ if (error)
return error;
- }
*filename = pb.string;
return 0;
if (rsync == NULL)
load_metadata_json();
- error = init_cache_pb(&pb, "tmp/a");
+ error = pb_init_cache(&pb, "tmp/a");
if (error)
return error;
error = create_dir_recursive(pb.string);
delete_node(child);
}
+static char *
+uri2luri(struct rpki_uri *uri)
+{
+ char const *luri;
+
+ luri = uri_get_local(uri) + strlen(config_get_local_repository());
+ while (luri[0] == '/')
+ luri++;
+
+ return pstrdup(luri);
+}
+
/**
* @changed only on HTTP.
*/
if (changed != NULL)
*changed = false;
- luri = pstrdup(uri_get_local(uri));
+ luri = uri2luri(uri);
token = strtok_r(luri, "/", &saveptr);
switch (uri_get_type(uri)) {
struct cache_node *node, *child, *tmp;
int error;
- if (init_cache_pb(&pb, NULL) != 0)
- goto end;
+ if (pb_init_cache(&pb, NULL) != 0)
+ return;
ctt_init(&ctt, root, &pb);
if ((*root) == NULL && pb_append(&pb, treename) == 0)
pb_rm_r(&pb, treename, true);
-end:
+
pb_cleanup(&pb);
}
#include <stdatomic.h>
-#include "config.h"
#include "data_structure/path_builder.h"
static atomic_uint file_counter;
struct path_builder pb;
int error;
- pb_init(&pb);
-
- error = pb_append(&pb, config_get_local_repository());
- if (error)
- return error;
- error = pb_append(&pb, "tmp");
+ error = pb_init_cache(&pb, "tmp");
if (error)
return error;
error = pb_append_u32(&pb, atomic_fetch_add(&file_counter, 1u));
#include <errno.h>
#include "alloc.h"
+#include "config.h"
#include "log.h"
#include "crypto/hash.h"
pb->capacity = INITIAL_CAPACITY;
}
+int
+pb_init_cache(struct path_builder *pb, char const *subdir)
+{
+ int error;
+
+ pb_init(pb);
+
+ error = pb_append(pb, config_get_local_repository());
+ if (error)
+ goto cancel;
+
+ error = pb_append(pb, subdir);
+ if (error)
+ goto cancel;
+
+ return 0;
+
+cancel:
+ pb_cleanup(pb);
+ return error;
+}
+
static int
pb_grow(struct path_builder *pb, size_t total_len, char const *addend)
{
};
void pb_init(struct path_builder *);
+int pb_init_cache(struct path_builder *, char const *);
/*
* The appends are atomic.
struct path_builder pb;
int error;
- pb_init(&pb);
+ error = pb_init_cache(&pb, NULL);
+ if (error)
+ return error;
+
error = append_guri(&pb, uri->global, gprefix, err, false);
if (error) {
pb_cleanup(&pb);
# Otherwise it must be included manually:
# mumble_mumble_CFLAGS = ${AM_CFLAGS} flag1 flag2 flag3 ...
AM_CFLAGS = -pedantic -Wall
+#AM_CFLAGS += -Wno-unused
AM_CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200809 -D_XOPEN_SOURCE=700
AM_CFLAGS += -I../src -DUNIT_TESTING ${CHECK_CFLAGS} ${XML2_CFLAGS}
# Reminder: As opposed to AM_CFLAGS, "AM_LDADD" is not idiomatic automake, and
return -EINVAL;
cmd = pmalloc(128);
- printed = snprintf(cmd, 128, "mkdir -p tmp/%s", uri_get_local(uri));
+ printed = snprintf(cmd, 128, "mkdir -p %s", uri_get_local(uri));
ck_assert(printed < 128);
ck_assert_int_eq(0, system(cmd));
cmd = pmalloc(128);
printed = snprintf(cmd, 128,
/* "create file, but only if it's not already a directory" */
- "test ! -d tmp/%s && install -D /dev/null tmp/%s",
+ "test ! -d %s && install -D /dev/null %s",
uri_get_local(uri), uri_get_local(uri));
ck_assert(printed < 128);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c"));
ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/"));
ck_assert_str_eq("https://a.b.c/", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/d"));
ck_assert_str_eq("https://a.b.c/d", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c/d", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c/d", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/d/e"));
ck_assert_str_eq("https://a.b.c/d/e", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c/d/e", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c/d/e", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/d/.."));
ck_assert_str_eq("https://a.b.c/d/..", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/."));
ck_assert_str_eq("https://a.b.c/.", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/././d/././e/./."));
ck_assert_str_eq("https://a.b.c/././d/././e/./.", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c/d/e", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c/d/e", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(0, uri_create(&uri, UT_HTTPS, "https://a.b.c/a/b/.././.."));
ck_assert_str_eq("https://a.b.c/a/b/.././..", uri_get_global(uri));
- ck_assert_str_eq("https/a.b.c", uri_get_local(uri));
+ ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
uri_refput(uri);
ck_assert_int_eq(-EINVAL, uri_create(&uri, UT_HTTPS, "https://a.b.c/.."));