1 #pragma once 2 3 #include "logging.hpp" 4 5 #include <filesystem> 6 #include <fstream> 7 8 namespace crow 9 { 10 namespace ibm_utils 11 { 12 13 inline bool createDirectory(std::string_view path) 14 { 15 // Create persistent directory 16 std::error_code ec; 17 18 BMCWEB_LOG_DEBUG("Creating persistent directory : {}", path); 19 20 bool dirCreated = std::filesystem::create_directories(path, ec); 21 22 if (ec) 23 { 24 BMCWEB_LOG_ERROR("Failed to create persistent directory : {}", path); 25 return false; 26 } 27 28 if (dirCreated) 29 { 30 // set the permission of the directory to 700 31 BMCWEB_LOG_DEBUG("Setting the permission to 700"); 32 std::filesystem::perms permission = std::filesystem::perms::owner_all; 33 std::filesystem::permissions(path, permission); 34 } 35 else 36 { 37 BMCWEB_LOG_DEBUG("{} already exists", path); 38 } 39 return true; 40 } 41 42 } // namespace ibm_utils 43 } // namespace crow 44