#include "rrdp/snapshot.h"
+#define _XOPEN_SOURCE 500
+#include <ftw.h>
+
#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)
{
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;
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);