summaryrefslogtreecommitdiff
path: root/src/utils/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/cpp')
-rw-r--r--src/utils/cpp/path.hpp13
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