diff --git a/lib/nodes/file.c b/lib/nodes/file.c index fad7f18b5..f0e71c707 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -210,6 +212,20 @@ int file_start(struct node *n) /* Prepare file name */ f->uri = file_format_name(f->uri_tmpl, &now); + /* Check if directory exists */ + struct stat sb; + char *dir = dirname(f->uri); + + ret = stat(dir, &sb); + if (ret) + serror("Failed to stat"); + + if (!S_ISDIR(sb.st_mode)) { + ret = mkdir(dir, 0644); + if (ret) + serror("Failed to create directory"); + } + /* Open file */ flags = SAMPLE_HAS_ALL; if (f->flush)