#include <stdbool.h>
#include <sys/queue.h>
#include <sys/stat.h>
+#include <unistd.h>
#include "alloc.h"
#include "cachetmp.h"
typedef int (*dl_cb)(struct cache_node *rpp);
struct cache_table {
- char const *name;
+ char *name;
bool enabled;
struct cache_sequence seq;
struct cache_node *nodes; /* Hash Table */
free(node);
}
-static char *
-get_cache_filename(char const *name, bool fatal)
-{
- struct path_builder pb;
- int error;
-
- error = pb_init_cache(&pb, name);
- if (error) {
- if (fatal) {
- pr_crit("Cannot create path to %s: %s", name,
- strerror(error));
- } else {
- pr_op_err("Cannot create path to %s: %s", name,
- strerror(error));
- return NULL;
- }
- }
-
- return pb.string;
-}
-
char *
get_rsync_module(char const *url)
{
static int dl_rrdp(struct cache_node *);
static void
-init_table(struct cache_table *tbl, char const *name, bool enabled, dl_cb dl)
+init_table(struct cache_table *tbl, char *name, bool enabled, dl_cb dl)
{
memset(tbl, 0, sizeof(*tbl));
tbl->name = name;
tbl->enabled = enabled;
- cseq_init(&tbl->seq, path_join(config_get_local_repository(), name));
+ cseq_init(&tbl->seq, name, false);
tbl->download = dl;
}
static void
init_cache_metafile(void)
{
- char *filename;
json_t *root;
json_error_t jerror;
char const *file_version;
int error;
- filename = get_cache_filename(CACHE_METAFILE, true);
- root = json_load_file(filename, 0, &jerror);
+ root = json_load_file(CACHE_METAFILE, 0, &jerror);
if (root == NULL) {
if (json_error_code(&jerror) == json_error_cannot_open_file)
- pr_op_debug("%s does not exist.", filename);
+ pr_op_debug(CACHE_METAFILE " does not exist.");
else
- pr_op_err("Json parsing failure at %s (%d:%d): %s",
- filename, jerror.line, jerror.column, jerror.text);
+ pr_op_err("Json parsing failure at " CACHE_METAFILE
+ " (%d:%d): %s", jerror.line, jerror.column,
+ jerror.text);
goto invalid_cache;
}
if (json_typeof(root) != JSON_OBJECT) {
- pr_op_err("The root tag of %s is not an object.", filename);
+ pr_op_err(CACHE_METAFILE "'s root tag is not an object.");
goto invalid_cache;
}
error = json_get_str(root, TAGNAME_VERSION, &file_version);
if (error) {
if (error > 0)
- pr_op_err("%s is missing the " TAGNAME_VERSION " tag.",
- filename);
+ pr_op_err(CACHE_METAFILE " is missing the "
+ TAGNAME_VERSION " tag.");
goto invalid_cache;
}
- if (strcmp(file_version, PACKAGE_VERSION) == 0)
- goto end;
+ if (strcmp(file_version, PACKAGE_VERSION) != 0)
+ goto invalid_cache;
-invalid_cache:
- pr_op_info("The cache appears to have been built by a different version of Fort. I'm going to clear it, just to be safe.");
- file_rm_rf(config_get_local_repository());
+ json_decref(root);
+ return;
-end: json_decref(root);
- free(filename);
+invalid_cache:
+ pr_op_info("The cache seems to have been built by a different version of Fort. "
+ "I'm going to clear it, just to be safe.");
+ file_rm_rf(".");
+ json_decref(root);
}
static void
init_cachedir_tag(void)
{
- char *filename;
-
- filename = get_cache_filename("CACHEDIR.TAG", false);
- if (filename == NULL)
- return;
-
+ static char const *filename = "CACHEDIR.TAG";
if (file_exists(filename) == ENOENT)
write_simple_file(filename,
"Signature: 8a477f597d28d172789f06886806bc55\n"
"# This file is a cache directory tag created by Fort.\n"
"# For information about cache directory tags, see:\n"
"# https://bford.info/cachedir/\n");
-
- free(filename);
}
static int
init_tmp_dir(void)
{
- char *dirname;
int error;
- dirname = get_cache_filename(CACHE_TMPDIR, true);
-
- if (mkdir(dirname, CACHE_FILEMODE) < 0) {
+ if (mkdir(CACHE_TMPDIR, CACHE_FILEMODE) < 0) {
error = errno;
if (error != EEXIST)
return pr_op_err("Cannot create '%s': %s",
- dirname, strerror(error));
+ CACHE_TMPDIR, strerror(error));
}
- free(dirname);
return 0;
}
int
cache_setup(void)
{
+ if (chdir(config_get_local_repository()) < 0) {
+ pr_op_err("Cannot cd to the cache directory: %s",
+ strerror(errno));
+ return errno;
+ }
+
// XXX Lock the cache directory
init_tables();
init_cache_metafile();
void
cache_teardown(void)
{
- char *filename;
-
- filename = get_cache_filename(CACHE_METAFILE, false);
- if (filename == NULL)
- return;
-
- write_simple_file(filename, "{ \"" TAGNAME_VERSION "\": \""
+ // XXX catch result?
+ write_simple_file(CACHE_METAFILE, "{ \"" TAGNAME_VERSION "\": \""
PACKAGE_VERSION "\" }\n");
- free(filename);
-}
-
-static char *
-get_tal_json_filename(void)
-{
- struct path_builder pb;
- return pb_init_cache(&pb, TAL_METAFILE) ? NULL : pb.string;
}
static struct cache_node *
static void
load_tal_json(void)
{
- char *filename;
json_t *root;
json_error_t jerror;
* without killing itself. It's just a cache of a cache.
*/
- filename = get_tal_json_filename();
- if (filename == NULL)
- return;
-
- pr_op_debug("Loading %s.", filename);
+ pr_op_debug("Loading " TAL_METAFILE ".");
- root = json_load_file(filename, 0, &jerror);
+ root = json_load_file(TAL_METAFILE, 0, &jerror);
if (root == NULL) {
if (json_error_code(&jerror) == json_error_cannot_open_file)
- pr_op_debug("%s does not exist.", filename);
+ pr_op_debug(TAL_METAFILE " does not exist.");
else
pr_op_err("Json parsing failure at %s (%d:%d): %s",
- filename, jerror.line, jerror.column, jerror.text);
+ TAL_METAFILE, jerror.line, jerror.column,
+ jerror.text);
goto end;
}
if (json_typeof(root) != JSON_OBJECT) {
- pr_op_err("The root tag of %s is not an object.", filename);
+ pr_op_err("The root tag of " TAL_METAFILE " is not an object.");
goto end;
}
json2tbl(root, &cache.fallback);
end: json_decref(root);
- free(filename);
}
void
static void
write_tal_json(void)
{
- char *filename;
struct json_t *json;
json = build_tal_json();
if (json == NULL)
return;
- filename = get_tal_json_filename();
- if (filename == NULL)
- goto end;
-
- if (json_dump_file(json, filename, JSON_INDENT(2)))
- pr_op_err("Unable to write %s; unknown cause.", filename);
+ if (json_dump_file(json, TAL_METAFILE, JSON_INDENT(2)))
+ pr_op_err("Unable to write " TAL_METAFILE "; unknown cause.");
-end: json_decref(json);
- free(filename);
+ json_decref(json);
}
static int
static void
cleanup_tmp(void)
{
- char *tmpdir = get_cache_filename(CACHE_TMPDIR, true);
- if (nftw(tmpdir, rmf, 32, FTW_DEPTH | FTW_PHYS))
+ if (nftw(CACHE_TMPDIR, rmf, 32, FTW_DEPTH | FTW_PHYS))
pr_op_warn("Cannot empty the cache's tmp directory: %s",
strerror(errno));
- free(tmpdir);
}
static bool
is_fallback(char const *path)
{
- // XXX just cd to the freaking cache, ffs
- path += strlen(config_get_local_repository());
- return str_starts_with(path, "fallback/") ||
- str_starts_with(path, "/fallback/");
+ return str_starts_with(path, "fallback/");
}
/* Hard-links @rpp's approved files into the fallback directory. */
{
// XXX no need to recurse anymore.
/*
- char *rootpath;
-
- rootpath = join_paths(config_get_local_repository(), "rsync");
-
nftw_root = cache.rsync;
- nftw(rootpath, nftw_remove_abandoned, 32, FTW_DEPTH | FTW_PHYS); // XXX
-
- strcpy(rootpath + strlen(rootpath) - 5, "https");
+ nftw("rsync", nftw_remove_abandoned, 32, FTW_DEPTH | FTW_PHYS); // XXX
nftw_root = cache.https;
- nftw(rootpath, nftw_remove_abandoned, 32, FTW_DEPTH | FTW_PHYS); // XXX
-
- free(rootpath);
+ nftw("https", nftw_remove_abandoned, 32, FTW_DEPTH | FTW_PHYS); // XXX
*/
}
cleanup_cache();
write_tal_json();
cache_foreach(delete_node);
- free(cache.rsync.seq.prefix);
- free(cache.https.seq.prefix);
- free(cache.rrdp.seq.prefix);
- free(cache.fallback.seq.prefix);
}
void
setup_test(void)
{
dl_error = 0;
- ck_assert_int_eq(0, system("rm -rf tmp"));
init_tables();
- ck_assert_int_eq(0, system("mkdir -p tmp/rsync tmp/https tmp/rrdp tmp/fallback"));
+ ck_assert_int_eq(0, system("rm -rf rsync/ https/ rrdp/ fallback/"));
+ ck_assert_int_eq(0, system("mkdir rsync/ https/ rrdp/ fallback/"));
}
static struct cache_cage *
printf("\n");
printf("Files in cache:\n");
- ck_assert_int_eq(0, nftw("tmp/", print_file, 32, FTW_PHYS));
+ ck_assert_int_eq(0, nftw(".", print_file, 32, FTW_PHYS));
printf("\n");
}
pr_op_debug("--- Unfreshening... ---");
cache_foreach(unfreshen);
- ck_assert_int_eq(0, nftw("tmp/rsync", nftw_unfreshen, 32, FTW_PHYS));
+ ck_assert_int_eq(0, nftw(".", nftw_unfreshen, 32, FTW_PHYS));
pr_op_debug("---- Tree now stale. ----");
cache_print();
printf("==== Startup ====\n");
cage = run_dl_rsync("rsync://a.b.c/d", 1);
ck_assert_ptr_ne(NULL, cage);
- ck_cage(cage, "rsync://a.b.c/d", "tmp/rsync/0", NULL);
- ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "tmp/rsync/0/e/f.cer", NULL);
- init_node_rsync(&nodes[0], "rsync://a.b.c/d", "tmp/rsync/0", 1, 0);
+ ck_cage(cage, "rsync://a.b.c/d", "rsync/0", NULL);
+ ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL);
+ init_node_rsync(&nodes[0], "rsync://a.b.c/d", "rsync/0", 1, 0);
ck_cache_rsync(nodes);
free(cage);
printf("==== Redownload same file, nothing should happen ====\n");
cage = run_dl_rsync("rsync://a.b.c/d", 0);
ck_assert_ptr_ne(NULL, cage);
- ck_cage(cage, "rsync://a.b.c/d", "tmp/rsync/0", NULL);
- ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "tmp/rsync/0/e/f.cer", NULL);
+ ck_cage(cage, "rsync://a.b.c/d", "rsync/0", NULL);
+ ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL);
ck_cache_rsync(nodes);
free(cage);
printf("==== Don't redownload child ====\n");
cage = run_dl_rsync("rsync://a.b.c/d/e", 0);
ck_assert_ptr_ne(NULL, cage);
- ck_cage(cage, "rsync://a.b.c/d", "tmp/rsync/0", NULL);
- ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "tmp/rsync/0/e/f.cer", NULL);
+ ck_cage(cage, "rsync://a.b.c/d", "rsync/0", NULL);
+ ck_cage(cage, "rsync://a.b.c/d/e/f.cer", "rsync/0/e/f.cer", NULL);
ck_cache_rsync(nodes);
free(cage);
printf("==== rsync truncated ====\n");
cage = run_dl_rsync("rsync://x.y.z/m/n/o", 1);
ck_assert_ptr_ne(NULL, cage);
- ck_cage(cage, "rsync://x.y.z/m", "tmp/rsync/1", NULL);
- ck_cage(cage, "rsync://x.y.z/m/n/o", "tmp/rsync/1/n/o", NULL);
- init_node_rsync(&nodes[1], "rsync://x.y.z/m", "tmp/rsync/1", 1, 0);
+ ck_cage(cage, "rsync://x.y.z/m", "rsync/1", NULL);
+ ck_cage(cage, "rsync://x.y.z/m/n/o", "rsync/1/n/o", NULL);
+ init_node_rsync(&nodes[1], "rsync://x.y.z/m", "rsync/1", 1, 0);
ck_cache_rsync(nodes);
free(cage);
printf("==== Sibling ====\n");
cage = run_dl_rsync("rsync://a.b.c/e/f", 1);
ck_assert_ptr_ne(NULL, cage);
- ck_cage(cage, "rsync://a.b.c/e", "tmp/rsync/2", NULL);
- ck_cage(cage, "rsync://a.b.c/e/f/x/y/z", "tmp/rsync/2/f/x/y/z", NULL);
- init_node_rsync(&nodes[2], "rsync://a.b.c/e", "tmp/rsync/2", 1, 0);
+ ck_cage(cage, "rsync://a.b.c/e", "rsync/2", NULL);
+ ck_cage(cage, "rsync://a.b.c/e/f/x/y/z", "rsync/2/f/x/y/z", NULL);
+ init_node_rsync(&nodes[2], "rsync://a.b.c/e", "rsync/2", 1, 0);
ck_cache_rsync(nodes);
free(cage);
setup_test();
- init_node_rsync(&nodes[0], "rsync://a.b.c/d", "tmp/rsync/0", 1, 0);
- init_node_rsync(&nodes[1], "rsync://a.b.c/e", "tmp/rsync/1", 1, EINVAL);
+ init_node_rsync(&nodes[0], "rsync://a.b.c/d", "rsync/0", 1, 0);
+ init_node_rsync(&nodes[1], "rsync://a.b.c/e", "rsync/1", 1, EINVAL);
printf("==== Startup ====\n");
dl_error = 0;
setup_test();
- ck_assert_int_eq(0, system("mkdir -p tmp/rsync/0 tmp/rsync/1 tmp/rsync/2 tmp/rsync/3"));
+ ck_assert_int_eq(0, system("mkdir rsync/0 rsync/1 rsync/2 rsync/3"));
/* RPP0: Will remain constant */
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/0/0", "A"));
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/0/1", "B"));
+ ck_assert_int_eq(0, write_simple_file("rsync/0/0", "A"));
+ ck_assert_int_eq(0, write_simple_file("rsync/0/1", "B"));
/* RPP1: Will be added in its second cycle */
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/1/0", "C"));
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/1/1", "D"));
+ ck_assert_int_eq(0, write_simple_file("rsync/1/0", "C"));
+ ck_assert_int_eq(0, write_simple_file("rsync/1/1", "D"));
/* RPP2: Will be removed in its second cycle */
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/2/0", "E"));
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/2/1", "F"));
+ ck_assert_int_eq(0, write_simple_file("rsync/2/0", "E"));
+ ck_assert_int_eq(0, write_simple_file("rsync/2/1", "F"));
/* RPP3: Will be updated in its second cycle */
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/3/0", "G")); /* Keeper */
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/3/1", "H")); /* Added */
- ck_assert_int_eq(0, write_simple_file("tmp/rsync/3/2", "I")); /* Removed */
+ ck_assert_int_eq(0, write_simple_file("rsync/3/0", "G")); /* Keeper */
+ ck_assert_int_eq(0, write_simple_file("rsync/3/1", "H")); /* Added */
+ ck_assert_int_eq(0, write_simple_file("rsync/3/2", "I")); /* Removed */
/* Commit 1: Empty -> Empty */
/* Commit 2: Empty -> Empty (just free noise) */
for (i = 0; i < 2; i++) {
commit_fallbacks();
- ck_filesystem("tmp/fallback", NULL);
+ ck_filesystem("fallback", NULL);
new_iteration(false);
}
/* Commit 3: Empty -> Populated */
- queue_commit("rsync://domain/mod/rpp0", "tmp/rsync/0/0", "tmp/rsync/0/1");
- queue_commit("rsync://domain/mod/rpp2", "tmp/rsync/2/0", "tmp/rsync/2/1");
- queue_commit("rsync://domain/mod/rpp3", "tmp/rsync/3/0", "tmp/rsync/3/2");
+ queue_commit("rsync://domain/mod/rpp0", "rsync/0/0", "rsync/0/1");
+ queue_commit("rsync://domain/mod/rpp2", "rsync/2/0", "rsync/2/1");
+ queue_commit("rsync://domain/mod/rpp3", "rsync/3/0", "rsync/3/2");
commit_fallbacks();
- ck_filesystem("tmp/fallback",
- /* RPP0 */ "tmp/fallback/0/0", "A", "tmp/fallback/0/1", "B",
- /* RPP2 */ "tmp/fallback/1/0", "E", "tmp/fallback/1/1", "F",
- /* RPP3 */ "tmp/fallback/2/0", "G", "tmp/fallback/2/1", "I",
+ ck_filesystem("fallback",
+ /* RPP0 */ "fallback/0/0", "A", "fallback/0/1", "B",
+ /* RPP2 */ "fallback/1/0", "E", "fallback/1/1", "F",
+ /* RPP3 */ "fallback/2/0", "G", "fallback/2/1", "I",
NULL);
new_iteration(false);
/* Commit 4: Populated -> Populated */
/* XXX check the refresh does, in fact, only return fallbacks when the RPP doesn't change */
- queue_commit("rsync://domain/mod/rpp0", "tmp/fallback/0/0", "tmp/fallback/0/1");
- queue_commit("rsync://domain/mod/rpp1", "tmp/rsync/1/0", "tmp/rsync/1/1");
- queue_commit("rsync://domain/mod/rpp3", "tmp/fallback/2/0", "tmp/rsync/3/1");
+ queue_commit("rsync://domain/mod/rpp0", "fallback/0/0", "fallback/0/1");
+ queue_commit("rsync://domain/mod/rpp1", "rsync/1/0", "rsync/1/1");
+ queue_commit("rsync://domain/mod/rpp3", "fallback/2/0", "rsync/3/1");
commit_fallbacks();
- ck_filesystem("tmp/fallback",
- /* RPP0 */ "tmp/fallback/0/0", "A", "tmp/fallback/0/1", "B",
- /* RPP3 */ "tmp/fallback/2/0", "G", "tmp/fallback/2/2", "H",
- /* RPP1 */ "tmp/fallback/3/0", "C", "tmp/fallback/3/1", "D",
+
+ ck_filesystem("fallback",
+ /* RPP0 */ "fallback/0/0", "A", "fallback/0/1", "B",
+ /* RPP3 */ "fallback/2/0", "G", "fallback/2/2", "H",
+ /* RPP1 */ "fallback/3/0", "C", "fallback/3/1", "D",
NULL);
new_iteration(false);
/* Commit 5: Populated -> Empty */
commit_fallbacks();
- ck_filesystem("tmp/fallback", NULL);
+ ck_filesystem("fallback", NULL);
cache_foreach(delete_node);
}
setup_test();
printf("==== Download file ====\n");
- run_dl_https("https://a.b.c/d/e", 1, "tmp/https/0");
- init_node_https(&nodes[0], "https://a.b.c/d/e", "tmp/https/0", 1, 0);
+ run_dl_https("https://a.b.c/d/e", 1, "https/0");
+ init_node_https(&nodes[0], "https://a.b.c/d/e", "https/0", 1, 0);
ck_cache_https(nodes);
printf("==== Download same file ====\n");
- run_dl_https("https://a.b.c/d/e", 0, "tmp/https/0");
+ run_dl_https("https://a.b.c/d/e", 0, "https/0");
ck_cache_https(nodes);
printf("==== Download something else 1 ====\n");
- run_dl_https("https://a.b.c/e", 1, "tmp/https/1");
- init_node_https(&nodes[1], "https://a.b.c/e", "tmp/https/1", 1, 0);
+ run_dl_https("https://a.b.c/e", 1, "https/1");
+ init_node_https(&nodes[1], "https://a.b.c/e", "https/1", 1, 0);
ck_cache_https(nodes);
printf("==== Download something else 2 ====\n");
- run_dl_https("https://x.y.z/e", 1, "tmp/https/2");
- init_node_https(&nodes[2], "https://x.y.z/e", "tmp/https/2", 1, 0);
+ run_dl_https("https://x.y.z/e", 1, "https/2");
+ init_node_https(&nodes[2], "https://x.y.z/e", "https/2", 1, 0);
ck_cache_https(nodes);
cleanup_test();
setup_test();
- init_node_https(&nodes[0], "https://a.b.c/d", "tmp/https/0", 1, 0);
- init_node_https(&nodes[1], "https://a.b.c/e", "tmp/https/1", 1, EINVAL);
+ init_node_https(&nodes[0], "https://a.b.c/d", "https/0", 1, 0);
+ init_node_https(&nodes[1], "https://a.b.c/e", "https/1", 1, EINVAL);
printf("==== Startup ====\n");
dl_error = 0;
- run_dl_https("https://a.b.c/d", 1, "tmp/https/0");
+ run_dl_https("https://a.b.c/d", 1, "https/0");
dl_error = EINVAL;
run_dl_https("https://a.b.c/e", 1, NULL);
ck_cache_https(nodes);
printf("==== Regardless of error, not reattempted because same iteration ====\n");
dl_error = -EINVAL;
- run_dl_https("https://a.b.c/d", 0, "tmp/https/0");
+ run_dl_https("https://a.b.c/d", 0, "https/0");
run_dl_https("https://a.b.c/e", 0, NULL);
dl_error = 0;
- run_dl_https("https://a.b.c/d", 0, "tmp/https/0");
+ run_dl_https("https://a.b.c/d", 0, "https/0");
run_dl_https("https://a.b.c/e", 0, NULL);
ck_cache_https(nodes);
setup_test();
- ck_assert_int_eq(0, write_simple_file("tmp/https/50", "A")); /* Keeper */
- ck_assert_int_eq(0, write_simple_file("tmp/https/51", "B")); /* Added */
- ck_assert_int_eq(0, write_simple_file("tmp/https/52", "C")); /* Removed */
+ ck_assert_int_eq(0, write_simple_file("https/50", "A")); /* Keeper */
+ ck_assert_int_eq(0, write_simple_file("https/51", "B")); /* Added */
+ ck_assert_int_eq(0, write_simple_file("https/52", "C")); /* Removed */
/* 1, 2 */
for (i = 0; i < 2; i++) {
commit_fallbacks();
- ck_filesystem("tmp/fallback", NULL);
+ ck_filesystem("fallback", NULL);
new_iteration(false);
}
/* 3 */
map.url = "https://domain/rpki/ta50.cer";
- map.path = "tmp/https/50";
+ map.path = "https/50";
cache_commit_file(&map);
map.url = "https://domain/rpki/ta52.cer";
- map.path = "tmp/https/52";
+ map.path = "https/52";
cache_commit_file(&map);
commit_fallbacks();
- ck_filesystem("tmp/fallback",
- "tmp/fallback/0", "A",
- "tmp/fallback/1", "C",
- NULL);
+ ck_filesystem("fallback", "fallback/0", "A", "fallback/1", "C", NULL);
new_iteration(false);
/* 4 */
map.url = "https://domain/rpki/ta50.cer";
- map.path = "tmp/fallback/0";
+ map.path = "fallback/0";
cache_commit_file(&map);
map.url = "https://domain/rpki/ta51.cer";
- map.path = "tmp/https/51";
+ map.path = "https/51";
cache_commit_file(&map);
commit_fallbacks();
- ck_filesystem("tmp/fallback",
- "tmp/fallback/0", "A",
- "tmp/fallback/2", "B",
- NULL);
+ ck_filesystem("fallback", "fallback/0", "A", "fallback/2", "B", NULL);
new_iteration(false);
/* 5 */
commit_fallbacks();
- ck_filesystem("tmp/fallback", NULL);
+ ck_filesystem("fallback", NULL);
cache_foreach(delete_node);
}
setup_test();
- ck_assert_int_eq(0, system("mkdir -p tmp/rrdp/0 tmp/rrdp/1 tmp/rrdp/2 tmp/rrdp/3"));
+ ck_assert_int_eq(0, system("mkdir rrdp/0 rrdp/1 rrdp/2 rrdp/3"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/0/0", "A"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/0/1", "B"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/1/0", "C"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/1/1", "D"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/2/0", "E"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/2/1", "F"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/3/0", "G"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/3/1", "H"));
- ck_assert_int_eq(0, write_simple_file("tmp/rrdp/3/2", "I"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/0/0", "A"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/0/1", "B"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/1/0", "C"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/1/1", "D"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/2/0", "E"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/2/1", "F"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/3/0", "G"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/3/1", "H"));
+ ck_assert_int_eq(0, write_simple_file("rrdp/3/2", "I"));
/* 1, 2 */
for (i = 0; i < 2; i++) {
commit_fallbacks();
- ck_filesystem("tmp/fallback", NULL);
+ ck_filesystem("fallback", NULL);
new_iteration(false);
}
/* 3 */
- queue_commit("rsync://domain/mod/rpp0", "tmp/rrdp/0/0", "tmp/rrdp/0/1");
- queue_commit("rsync://domain/mod/rpp2", "tmp/rrdp/2/0", "tmp/rrdp/2/1");
- queue_commit("rsync://domain/mod/rpp3", "tmp/rrdp/3/0", "tmp/rrdp/3/2");
+ queue_commit("rsync://domain/mod/rpp0", "rrdp/0/0", "rrdp/0/1");
+ queue_commit("rsync://domain/mod/rpp2", "rrdp/2/0", "rrdp/2/1");
+ queue_commit("rsync://domain/mod/rpp3", "rrdp/3/0", "rrdp/3/2");
commit_fallbacks();
- ck_filesystem("tmp/fallback",
- "tmp/fallback/0/0", "A", "tmp/fallback/0/1", "B",
- "tmp/fallback/1/0", "E", "tmp/fallback/1/1", "F",
- "tmp/fallback/2/0", "G", "tmp/fallback/2/1", "I",
+ ck_filesystem("fallback",
+ "fallback/0/0", "A", "fallback/0/1", "B",
+ "fallback/1/0", "E", "fallback/1/1", "F",
+ "fallback/2/0", "G", "fallback/2/1", "I",
NULL);
new_iteration(false);
/* 4 */
- queue_commit("rsync://domain/mod/rpp0", "tmp/fallback/0/0", "tmp/fallback/0/1");
- queue_commit("rsync://domain/mod/rpp1", "tmp/rrdp/1/0", "tmp/rrdp/1/1");
- queue_commit("rsync://domain/mod/rpp3", "tmp/fallback/2/0", "tmp/rrdp/3/1");
+ queue_commit("rsync://domain/mod/rpp0", "fallback/0/0", "fallback/0/1");
+ queue_commit("rsync://domain/mod/rpp1", "rrdp/1/0", "rrdp/1/1");
+ queue_commit("rsync://domain/mod/rpp3", "fallback/2/0", "rrdp/3/1");
commit_fallbacks();
- ck_filesystem("tmp/fallback",
- "tmp/fallback/0/0", "A", "tmp/fallback/0/1", "B",
- "tmp/fallback/2/0", "G", "tmp/fallback/2/2", "H",
- "tmp/fallback/3/0", "C", "tmp/fallback/3/1", "D",
+ ck_filesystem("fallback",
+ "fallback/0/0", "A", "fallback/0/1", "B",
+ "fallback/2/0", "G", "fallback/2/2", "H",
+ "fallback/3/0", "C", "fallback/3/1", "D",
NULL);
new_iteration(false);
/* 5 */
commit_fallbacks();
- ck_filesystem("tmp/fallback", NULL);
+ ck_filesystem("fallback", NULL);
cache_foreach(delete_node);
}
SRunner *runner;
int tests_failed;
- suite = create_suite();
dls[0] = "Fort\n";
+ if (mkdir("tmp", CACHE_FILEMODE) < 0 && errno != EEXIST) {
+ fprintf(stderr, "mkdir('tmp/'): %s\n", strerror(errno));
+ return 1;
+ }
+ if (chdir("tmp") < 0) {
+ fprintf(stderr, "chdir('tmp/'): %s\n", strerror(errno));
+ return 1;
+ }
+
+ suite = create_suite();
runner = srunner_create(suite);
srunner_run_all(runner, CK_NORMAL);