mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
file: create directory if does not exist yet
This commit is contained in:
parent
139ca2a3f8
commit
ed27d25823
1 changed files with 16 additions and 0 deletions
|
@ -23,6 +23,8 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <villas/nodes/file.h>
|
||||
#include <villas/utils.h>
|
||||
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue