diff options
author | Sunitha Harish <sunharis@in.ibm.com> | 2020-10-13 09:21:48 +0300 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2021-04-20 07:09:22 +0300 |
commit | 3e919b5857555e95d5348028bdc7393b9a1eca1a (patch) | |
tree | 5a4e39c57112c51c8e19b428e5c8d0fa87e7f321 /include/ibm/utils.hpp | |
parent | b295bf951f391380e60234d0fe6df7ad4f5b00c9 (diff) | |
download | bmcweb-3e919b5857555e95d5348028bdc7393b9a1eca1a.tar.xz |
Create IBM ConfigFile base directory
The ConfigFile upload fails when the /var/lib/obmc directory is not
available at BMC
This commit changes the base directory to /var/lib/bmcweb
The subdirectories for the configfiles and locks
are created under this new path
Migration strategy of this directory and files:
This is IBM only feature, compiled under the IBM_MANAGEMENT_CONSOLE flag
There is no system out yet which is running this code
Internal IBM stake holders are in agreement with the changes
Tested by :
1. Tested configfile upload on a BMC where the base directory is not
available
2. Tested the configfile upload on a factory BMC. Verified it creates
the base directories and the upload is successful
3. Tested the configfile usecases for delete and delete-all
4. Tested the acquire-lock functionality
5. Ran lock unit test successfully
Signed-off-by: Sunitha Harish <sunharis@in.ibm.com>
Change-Id: Ic3f5f5d0ba0b37950fd397ec835b4fa7babdaa9b
Diffstat (limited to 'include/ibm/utils.hpp')
-rw-r--r-- | include/ibm/utils.hpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/include/ibm/utils.hpp b/include/ibm/utils.hpp new file mode 100644 index 0000000000..217b2f4d1a --- /dev/null +++ b/include/ibm/utils.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include <logging.hpp> + +#include <filesystem> +#include <fstream> + +namespace crow +{ +namespace ibm_utils +{ + +inline bool createDirectory(const std::string_view path) +{ + // Create persistent directory + std::error_code ec; + + BMCWEB_LOG_DEBUG << "Creating persistent directory : " << path; + + bool dirCreated = std::filesystem::create_directories(path, ec); + + if (ec) + { + BMCWEB_LOG_ERROR << "Failed to create persistent directory : " << path; + return false; + } + + if (dirCreated) + { + // set the permission of the directory to 700 + BMCWEB_LOG_DEBUG << "Setting the permission to 700"; + std::filesystem::perms permission = std::filesystem::perms::owner_all; + std::filesystem::permissions(path, permission); + } + else + { + BMCWEB_LOG_DEBUG << path << " already exists"; + } + return true; +} + +} // namespace ibm_utils +} // namespace crow |