blob: bb439ee423d3d07376c6a166d3effd822d7c1703 [file] [log] [blame]
Sunitha Harish3e919b52020-10-13 01:21:48 -05001#pragma once
2
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08003#include "logging.hpp"
Sunitha Harish3e919b52020-10-13 01:21:48 -05004
5#include <filesystem>
6#include <fstream>
7
8namespace crow
9{
10namespace ibm_utils
11{
12
Ed Tanous26ccae32023-02-16 10:28:44 -080013inline bool createDirectory(std::string_view path)
Sunitha Harish3e919b52020-10-13 01:21:48 -050014{
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