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