From: Alberto Leiva Popper Date: Wed, 2 Feb 2022 23:56:40 +0000 (-0600) Subject: RRDP: Clear RPPs before exploding snapshots into them X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=780b69c9ef0edb55b31a1bccb847c931c8bb011d;p=thirdparty%2FFORT-validator.git RRDP: Clear RPPs before exploding snapshots into them --- diff --git a/src/data_structure/path_builder.c b/src/data_structure/path_builder.c index 51c6d342..32e1ca35 100644 --- a/src/data_structure/path_builder.c +++ b/src/data_structure/path_builder.c @@ -71,6 +71,9 @@ path_append_url(struct path_builder *pb, char const *guri) { char *colon; + if (guri == NULL) + return; + /* Is there really a point to removing the colon? */ colon = strchr(guri, ':'); if (colon != NULL) { diff --git a/src/rrdp/snapshot.c b/src/rrdp/snapshot.c index 21313f85..5ee1290c 100644 --- a/src/rrdp/snapshot.c +++ b/src/rrdp/snapshot.c @@ -1,9 +1,45 @@ #include "rrdp/snapshot.h" +#define _XOPEN_SOURCE 500 +#include + #include "thread_var.h" #include "http/http.h" #include "xml/relax_ng.h" +static int +rm_file(const char *fpath, const struct stat *sb, int typeflag, + struct FTW *ftwbuf) +{ + int error; + + error = remove(fpath); + if (error) { + pr_val_errno(errno, "Could not clean file or directory '%s'", + fpath); + } + + return error; +} + +/* Deletes (if any) all the old files from the RPP owned by @notif. */ +static int +clear_caged_directory(struct rrdp_notification *notif) +{ + struct rpki_uri *cage; + int error; + + error = uri_create_caged(NULL, notif, &cage); + if (error) + return error; + + pr_val_debug("Making sure '%s' is empty.", uri_get_local(cage)); + error = nftw(uri_get_local(cage), rm_file, 32, FTW_DEPTH | FTW_PHYS); + + uri_refput(cage); + return error; +} + static int xml_read_snapshot(xmlTextReaderPtr reader, void *arg) { @@ -12,8 +48,6 @@ xml_read_snapshot(xmlTextReaderPtr reader, void *arg) struct rrdp_notification *notif; xmlChar const *name; - /* TODO (aaaa) probably make sure the directory is empty before exploding */ - if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) return 0; @@ -47,6 +81,10 @@ rrdp_parse_snapshot(struct rrdp_notification *notification) if (error) goto pop; + error = clear_caged_directory(notification); + if (error) + goto pop; + error = relax_ng_parse(uri_get_local(uri), xml_read_snapshot, notification);