blob: 217b2f4d1a3c74b3978c3e923cb788270d5f47eb [file] [log] [blame]
Sunitha Harish3e919b52020-10-13 01:21:48 -05001#pragma once
2
3#include <logging.hpp>
4
5#include <filesystem>
6#include <fstream>
7
8namespace crow
9{
10namespace ibm_utils
11{
12
13inline 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