Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 3 | #include "logging.hpp" |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 4 | |
| 5 | #include <filesystem> |
| 6 | #include <fstream> |
| 7 | |
| 8 | namespace crow |
| 9 | { |
| 10 | namespace ibm_utils |
| 11 | { |
| 12 | |
| 13 | inline bool createDirectory(const 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 << path << " already exists"; |
| 38 | } |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | } // namespace ibm_utils |
| 43 | } // namespace crow |