create directory: final arg to control full path or prefix

Give SCCreateDirectoryTree a new argument, final. If true the
full path will be created as a directory. If false, the last
component will not be created as a directory (current
behaviour).
pull/3175/head
Jason Ish 7 years ago
parent 0d558ddc27
commit c0ffe4055a

@ -267,7 +267,7 @@ SCLogOpenFileFp(const char *path, const char *append_setting, uint32_t mode)
return NULL;
}
int rc = SCCreateDirectoryTree(filename);
int rc = SCCreateDirectoryTree(filename, false);
if (rc < 0) {
SCFree(filename);
return NULL;

@ -66,12 +66,24 @@ int PathIsRelative(const char *path)
return PathIsAbsolute(path) ? 0 : 1;
}
/** \brief Recursively create missing log directories.
* \param path path to log file
/**
* \brief Wrapper around SCMkDir with default mode arguments.
*/
int SCDefaultMkDir(const char *path)
{
return SCMkDir(path, S_IRWXU | S_IRGRP | S_IXGRP);
}
/**
* \brief Recursively create a directory.
*
* \param path Path to create
* \param final true will create the final path component, false will not
*
* \retval 0 on success
* \retval -1 on error
*/
int SCCreateDirectoryTree(const char *path)
int SCCreateDirectoryTree(const char *path, const bool final)
{
char pathbuf[PATH_MAX];
char *p;
@ -88,7 +100,7 @@ int SCCreateDirectoryTree(const char *path)
/* Truncate, while creating directory */
*p = '\0';
if (SCMkDir(pathbuf, S_IRWXU | S_IRGRP | S_IXGRP) != 0) {
if (SCDefaultMkDir(pathbuf) != 0) {
if (errno != EEXIST) {
return -1;
}
@ -98,5 +110,13 @@ int SCCreateDirectoryTree(const char *path)
}
}
if (final) {
if (SCDefaultMkDir(pathbuf) != 0) {
if (errno != EEXIST) {
return -1;
}
}
}
return 0;
}

@ -33,6 +33,7 @@
int PathIsAbsolute(const char *);
int PathIsRelative(const char *);
int SCCreateDirectoryTree(const char *path);
int SCDefaultMkDir(const char *path);
int SCCreateDirectoryTree(const char *path, const bool final);
#endif /* __UTIL_PATH_H__ */

Loading…
Cancel
Save