From e78daee3c4c91bc4f92a5ec21c7632dd3e332e46 Mon Sep 17 00:00:00 2001 From: atraczyk <andreastraczyk@gmail.com> Date: Tue, 23 Aug 2016 09:01:01 -0400 Subject: [PATCH] file system: create folders if they don't exist Change-Id: Ie84e5301a8726ef7652197c0fa5b771c94a4bdec --- src/fileutils.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 89ac21191d..7d6b41d4b2 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -381,8 +381,14 @@ get_cache_dir() std::vector<std::string> paths; emitSignal<DRing::ConfigurationSignal::GetAppDataPath>(&paths); if (not paths.empty()) - cache_path = paths[0]; - return cache_path + DIR_SEPARATOR_STR + std::string(".cache"); + cache_path = paths[0] + DIR_SEPARATOR_STR + std::string(".cache"); + + if (fileutils::recursive_mkdir(cache_path.data(), 0700) != true) { + // If directory creation failed + if (errno != EEXIST) + RING_DBG("Cannot create directory: %s!", cache_path.c_str()); + } + return cache_path; #else const std::string cache_home(XDG_CACHE_HOME); @@ -470,8 +476,14 @@ get_data_dir() std::vector<std::string> paths; emitSignal<DRing::ConfigurationSignal::GetAppDataPath>(&paths); if (not paths.empty()) - files_path = paths[0]; - return files_path + DIR_SEPARATOR_STR + std::string(".data"); + files_path = paths[0] + DIR_SEPARATOR_STR + std::string(".data"); + + if (fileutils::recursive_mkdir(files_path.data(), 0700) != true) { + // If directory creation failed + if (errno != EEXIST) + RING_DBG("Cannot create directory: %s!", files_path.c_str()); + } + return files_path; #else const std::string data_home(XDG_DATA_HOME); if (not data_home.empty()) @@ -501,8 +513,14 @@ get_config_dir() std::vector<std::string> paths; emitSignal<DRing::ConfigurationSignal::GetAppDataPath>(&paths); if (not paths.empty()) - files_path = paths[0]; - return files_path + DIR_SEPARATOR_STR + std::string(".config"); + config_path = paths[0] + DIR_SEPARATOR_STR + std::string(".config"); + + if (fileutils::recursive_mkdir(config_path.data(), 0700) != true) { + // If directory creation failed + if (errno != EEXIST) + RING_DBG("Cannot create directory: %s!", config_path.c_str()); + } + return config_path; #else std::string configdir = fileutils::get_home_dir() + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR + PACKAGE; -- GitLab