#include <time.h>
#include "alloc.h"
+#include "common.h"
#include "config.h"
#include "file.h"
#include "log.h"
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;
- pb_init(&pb);
- error = pb_append(&pb, config_get_local_repository());
- if (error)
- goto cancel;
- error = pb_append(&pb, "metadata.json");
- if (error)
- goto cancel;
+ error = init_cache_pb(&pb, "metadata.json");
+ if (error) {
+ pb_cleanup(&pb);
+ return error;
+ }
*filename = pb.string;
return 0;
-
-cancel:
- pb_cleanup(&pb);
- return error;
}
static int
json_decref(root);
}
-void
+int
cache_prepare(void)
{
+ struct path_builder pb;
+ int error;
+
startup_time = time(NULL);
if (startup_time == ((time_t) -1))
pr_crit("time(NULL) returned -1");
if (rsync == NULL)
load_metadata_json();
+
+ error = init_cache_pb(&pb, "tmp/a");
+ if (error)
+ return error;
+ error = create_dir_recursive(pb.string);
+ pb_cleanup(&pb);
+ return error;
}
static int
struct cache_node *node, *child, *tmp;
int error;
- pb_init(&pb);
- if (pb_append(&pb, config_get_local_repository()) != 0)
+ if (init_cache_pb(&pb, NULL) != 0)
goto end;
ctt_init(&ctt, root, &pb);
#include "types/uri.h"
/* Warms up cache for new validation run */
-void cache_prepare(void);
+int cache_prepare(void);
/* Downloads @uri into the cache */
int cache_download(struct rpki_uri *uri, bool *);
}
static int
-create_dir(char *path)
+create_dir(char const *path)
{
int error;
int
pb_append(struct path_builder *pb, char const *addend)
{
- return pb_appendn(pb, addend, strlen(addend));
+ return (addend != NULL)
+ ? pb_appendn(pb, addend, strlen(addend))
+ : 0;
}
int
setopt_writedata(handler.curl, &args);
pr_val_info("HTTP GET: %s", src);
- res = curl_easy_perform(handler.curl);
+ res = curl_easy_perform(handler.curl); /* write_callback() */
if (args.file != NULL)
file_close(args.file);
pr_val_debug("Done. Total bytes transferred: %zu", args.total_bytes);
struct db_table *db;
int error;
- cache_prepare();
+ error = cache_prepare();
+ if (error)
+ return error;
db = db_table_create();
static void
__cache_prepare(void)
{
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
/* Ensure the old ts_successes and ts_attempts are outdated */
backtrack_times(rsync);
backtrack_times(https);
ck_assert_int_eq(0, system("rm -rf tmp/"));
dl_error = false;
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
download_rsync("rsync://a.b.c/d/e", 0, 1);
validate_tree(rsync,
{
ck_assert_int_eq(0, system("rm -rf tmp/"));
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
dl_error = false;
download_rsync("rsync://a.b.c/d", 0, 1);
{
ck_assert_int_eq(0, system("rm -rf tmp/"));
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
/* Set up */
dl_error = false;
ck_assert_int_eq(0, system("rm -rf tmp/"));
dl_error = false;
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
/* Download *file* e. */
download_https("https://a.b.c/d/e", 0, 1);
{
ck_assert_int_eq(0, system("rm -rf tmp/"));
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
dl_error = false;
download_https("https://a.b.c/d", 0, 1);
{
ck_assert_int_eq(0, system("rm -rf tmp/"));
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
/* Set up */
dl_error = false;
ck_assert_int_eq(0, system("rm -rf tmp/"));
dl_error = false;
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
download_https("https://a.b.c/d", 0, 1);
validate_tree(https,
ck_assert_int_eq(0, system("rm -rf tmp/"));
- cache_prepare();
+ ck_assert_int_eq(0, cache_prepare());
now = time(NULL);
if (now == ((time_t) -1))
ck_abort_msg("time(NULL) returned -1");