diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-05-30 17:57:21 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-06-26 17:57:29 +0200 |
commit | 0b924c5c23a89760ddecf8d8f6baa19333f9b667 (patch) | |
tree | 53be66938dcfd1f38a7dea98566e6de39d6df10f /src/utils/cpp | |
parent | b94f1b857c6bc1eab909c4fb9a0ba569d6d28a03 (diff) | |
download | justbuild-0b924c5c23a89760ddecf8d8f6baa19333f9b667.tar.gz |
filesystem: Add logic for handling (non-upwards) symlinks
Diffstat (limited to 'src/utils/cpp')
-rw-r--r-- | src/utils/cpp/path.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/utils/cpp/path.hpp b/src/utils/cpp/path.hpp index d872535e..a9fb08e5 100644 --- a/src/utils/cpp/path.hpp +++ b/src/utils/cpp/path.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_UTILS_CPP_PATH_HPP #include <filesystem> +#include <sstream> [[nodiscard]] static inline auto ToNormalPath(std::filesystem::path const& p) -> std::filesystem::path { @@ -29,4 +30,16 @@ return n; } +/// \brief Perform a non-upwards condition check on the given path. +/// A path is non-upwards if it is relative and it never references any other +/// path on a higher level in the directory tree than itself. +[[nodiscard]] static auto PathIsNonUpwards( + std::filesystem::path const& path) noexcept -> bool { + if (path.is_absolute()) { + return false; + } + // check non-upwards condition + return *path.lexically_normal().begin() != ".."; +} + #endif |