From 5f2eaa88e0583f8ccf5f218afa7508b281352e37 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Fri, 2 Nov 2018 15:37:56 +0100 Subject: Create the config directory if needed --- sdn.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sdn.cpp b/sdn.cpp index d5b56d3..30d716e 100644 --- a/sdn.cpp +++ b/sdn.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -252,9 +253,11 @@ fun xdg_config_find (const string &suffix) -> unique_ptr { fun xdg_config_write (const string &suffix) -> unique_ptr { 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 (move (fs)); } return nullptr; -- cgit v1.2.3-70-g09d2