diff options
author | Přemysl Janouch <p@janouch.name> | 2018-11-02 15:37:56 +0100 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-11-02 15:37:56 +0100 |
commit | 5f2eaa88e0583f8ccf5f218afa7508b281352e37 (patch) | |
tree | f63ebea7ae296c30ff61ca46fffdd1d97e470547 | |
parent | d6846e63276365ae554671621532a4f63a86cbf4 (diff) | |
download | sdn-5f2eaa88e0583f8ccf5f218afa7508b281352e37.tar.gz sdn-5f2eaa88e0583f8ccf5f218afa7508b281352e37.tar.xz sdn-5f2eaa88e0583f8ccf5f218afa7508b281352e37.zip |
Create the config directory if needed
-rw-r--r-- | sdn.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -38,6 +38,7 @@ #include <fcntl.h> #include <pwd.h> #include <grp.h> +#include <libgen.h> #include <sys/inotify.h> #include <sys/xattr.h> @@ -252,9 +253,11 @@ fun xdg_config_find (const string &suffix) -> unique_ptr<ifstream> { fun xdg_config_write (const string &suffix) -> unique_ptr<fstream> { auto dir = xdg_config_home (); if (dir[0] == '/') { - // TODO: try to create the end directory - if (fstream fs {dir + "/" PROJECT_NAME "/" + suffix, - fstream::in | fstream::out | fstream::trunc}) + auto path = dir + "/" PROJECT_NAME "/" + suffix; + if (!fork ()) + _exit (-execlp ("mkdir", "mkdir", "-p", + dirname (strdup (path.c_str ())), NULL)); + if (fstream fs {path, fstream::in | fstream::out | fstream::trunc}) return make_unique<fstream> (move (fs)); } return nullptr; |