}
static int
-dir_exists(char const *path, bool *result)
+dir_exists(char const *_path, bool *result)
{
- struct stat _stat;
+ char *path;
char *last_slash;
+ struct stat _stat;
+ int error;
+
+ /*
+ * Need to remove the const, otherwise "= '\0'" below causes undefined
+ * behavior.
+ */
+ path = strdup(_path);
+ if (path == NULL)
+ return pr_enomem();
last_slash = strrchr(path, '/');
if (last_slash == NULL) {
+ free(path);
/*
* Simply because create_dir_recursive() has nothing meaningful
* to do when this happens. It's a pretty strange error.
if (stat(path, &_stat) == 0) {
if (!S_ISDIR(_stat.st_mode)) {
- return pr_op_err("Path '%s' exists and is not a directory.",
+ error = pr_op_err("Path '%s' exists and is not a directory.",
path);
+ free(path);
+ return error;
}
*result = true;
} else if (errno == ENOENT) {
*result = false;
} else {
- return pr_op_errno(errno, "stat() failed");
+ error = errno;
+ free(path);
+ return pr_op_errno(error, "stat() failed");
}
- *last_slash = '/';
+ free(path);
return 0;
}
* Return values:
*
* - 0: Download successful.
- * - ENOTCHANGED: File hasn't changed since `args->ims`.
+ * - ENOTCHANGED: File hasn't changed since @ims.
* - < 0: Something went wrong.
*/
int
name = xmlTextReaderConstLocalName(reader);
if (xmlStrEqual(name, PUBLISH))
- return handle_publish_tag(reader, true, ctx->notification);
+ return handle_publish_tag(reader, ctx->notification, true);
if (xmlStrEqual(name, WITHDRAW))
return handle_withdraw_tag(reader, ctx->notification);
if (xmlStrEqual(name, DELTA)) {
#include "rrdp/snapshot.h"
#define _XOPEN_SOURCE 500
+#define __USE_XOPEN_EXTENDED 1
#include <ftw.h>
#include "thread_var.h"
struct rpki_uri *cage;
int error;
- error = uri_create_caged(NULL, notif, &cage);
+ error = uri_create_caged(NULL, notif->uri, &cage);
if (error)
return error;
file = uri_get_local(publish->target.uri);
- /*
- * TODO (aaaa) shouldn't this be reverted on error?
- * Also, shouldn't create_dir_recursive() be inside file_write()?
- */
error = create_dir_recursive(file);
if (error)
return error;
-
error = file_write(file, &out);
if (error)
return error;
file_close(out);
+ /* fwrite does not yield an error message... */
if (written != (sizeof(unsigned char) * publish->content_len))
return pr_val_err("Couldn't write bytes to file '%s'", file);
int parse_header_tag(xmlTextReaderPtr, struct rrdp_session *);
int validate_header_tag(xmlTextReaderPtr, struct rrdp_session *);
-int handle_publish_tag(xmlTextReaderPtr, struct rrdp_notification *);
+int handle_publish_tag(xmlTextReaderPtr, struct rrdp_notification *, bool);
#endif /* SRC_RRDP_TYPES_H_ */