summaryrefslogtreecommitdiff
path: root/src/utils/cpp/path.hpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2025-02-24 13:37:54 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2025-03-10 16:28:59 +0100
commitfa8c876031e4bc96c21f7f4d2f9161b1e5f64da7 (patch)
tree7b927d0e91738c485c4a6a80c588e7bbf87191b9 /src/utils/cpp/path.hpp
parent21af38d3aa8fb70172d1951d68823c11d61c5c05 (diff)
downloadjustbuild-fa8c876031e4bc96c21f7f4d2f9161b1e5f64da7.tar.gz
Promote IsValidFileName to a public function of the path utils
... instead of being private to parse_archive.
Diffstat (limited to 'src/utils/cpp/path.hpp')
-rw-r--r--src/utils/cpp/path.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils/cpp/path.hpp b/src/utils/cpp/path.hpp
index 26d25e50..ba3d125b 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 <string>
[[nodiscard]] static inline auto ToNormalPath(
std::filesystem::path const& p) noexcept -> std::filesystem::path {
@@ -58,4 +59,15 @@
return PathIsNonUpwards(applied_to.parent_path() / path);
}
+/// \brief Predicate if a given string is a valid filename.
+[[nodiscard]] static inline auto IsValidFileName(const std::string& s) -> bool {
+ if (s.find_first_of("/\0") != std::string::npos) {
+ return false;
+ }
+ if (s.empty() or s == "." or s == "..") {
+ return false;
+ }
+ return true;
+}
+
#endif // INCLUDED_SRC_UTILS_CPP_PATH_HPP