From 21450d62522a0a341375f70f9a8634c99ac60b32 Mon Sep 17 00:00:00 2001 From: Andreas Joachim Peters Date: Wed, 24 Jul 2024 15:27:08 +0200 Subject: [PATCH] XrdApps::JCache: add new 'Hierarchy.hh' file --- .../XrdClJCachePlugin/file/Hierarchy.hh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/XrdApps/XrdClJCachePlugin/file/Hierarchy.hh diff --git a/src/XrdApps/XrdClJCachePlugin/file/Hierarchy.hh b/src/XrdApps/XrdClJCachePlugin/file/Hierarchy.hh new file mode 100644 index 00000000000..2eac689a44b --- /dev/null +++ b/src/XrdApps/XrdClJCachePlugin/file/Hierarchy.hh @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2024 by European Organization for Nuclear Research (CERN) +// Author: Andreas-Joachim Peters +//------------------------------------------------------------------------------ +// This file is part of the XRootD software suite. +// +// XRootD is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// XRootD is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with XRootD. If not, see . +// +// In applying this licence, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#pragma once + +#include +#include +#include + +namespace JCache { + +bool makeHierarchy(const std::string &path) { + std::filesystem::path dirPath(path); + + try { + // Create the directories with 755 permissions + if (!std::filesystem::exists(dirPath)) { + std::filesystem::create_directories(dirPath.parent_path()); + + for (auto &p : std::filesystem::recursive_directory_iterator( + dirPath.parent_path())) { + if (std::filesystem::is_directory(p)) { + chmod(p.path().c_str(), 0755); + } + } + } + return true; + } catch (const std::filesystem::filesystem_error &e) { + // Handle error + std::cerr << "Filesystem error: " << e.what() << std::endl; + return false; + } catch (const std::exception &e) { + // Handle other errors + std::cerr << "Error: " << e.what() << std::endl; + return false; + } +} + +} // namespace JCache