From 770bc0491eb07ceac0e291db4838651da999ad5e Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 10 Jul 2025 15:26:32 -0700 Subject: [PATCH] Remove ghc::filesystem submodule, switch to std::filesystem --- .gitmodules | 3 --- CMakeLists.txt | 10 ---------- COPYING-3rdparty | 26 -------------------------- NEWS | 6 ++++++ auxil/filesystem | 1 - src/MMDB.h | 2 ++ src/ScannedFile.cc | 3 ++- src/logging/writers/ascii/Ascii.cc | 11 ++++++----- src/logging/writers/sqlite/SQLite.cc | 3 ++- src/scan.l | 3 ++- src/storage/backend/sqlite/SQLite.cc | 3 ++- src/util.cc | 21 +++++++++++---------- src/util.h | 15 +++++---------- 13 files changed, 38 insertions(+), 69 deletions(-) delete mode 160000 auxil/filesystem diff --git a/.gitmodules b/.gitmodules index 33e7d94136..73f8a0aead 100644 --- a/.gitmodules +++ b/.gitmodules @@ -58,9 +58,6 @@ [submodule "auxil/spicy"] path = auxil/spicy url = https://github.com/zeek/spicy -[submodule "auxil/filesystem"] - path = auxil/filesystem - url = https://github.com/gulrak/filesystem.git [submodule "auxil/zeek-af_packet-plugin"] path = auxil/zeek-af_packet-plugin url = https://github.com/zeek/zeek-af_packet-plugin.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a1aff11a5..18a2072853 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1057,9 +1057,6 @@ include(BuiltInSpicyAnalyzer) include_directories(BEFORE ${PCAP_INCLUDE_DIR} ${BIND_INCLUDE_DIR} ${BinPAC_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${JEMALLOC_INCLUDE_DIR}) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/auxil/filesystem/include/ghc - DESTINATION include/zeek/3rdparty/) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp/core/include/prometheus DESTINATION include/zeek/3rdparty/prometheus-cpp/include) @@ -1069,15 +1066,8 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/auxil/prometheus-cpp/core/include/ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/auxil/expected-lite/include/nonstd DESTINATION include/zeek/3rdparty/) -# Create 3rdparty/ghc within the build directory so that the include for -# "zeek/3rdparty/ghc/filesystem.hpp" works within the build tree. execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/3rdparty/") -execute_process( - COMMAND - "${CMAKE_COMMAND}" -E create_symlink - "${CMAKE_CURRENT_SOURCE_DIR}/auxil/filesystem/include/ghc" - "${CMAKE_CURRENT_BINARY_DIR}/3rdparty/ghc") # Do the same for nonstd. execute_process( diff --git a/COPYING-3rdparty b/COPYING-3rdparty index 627b86c644..764986bc1e 100644 --- a/COPYING-3rdparty +++ b/COPYING-3rdparty @@ -533,32 +533,6 @@ POSSIBILITY OF SUCH DAMAGE. ============================================================================== -%%% auxil/filesystem - -============================================================================== - -Copyright (c) 2018, Steffen Schümann - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -============================================================================== - %%% auxil/highwayhash ============================================================================== diff --git a/NEWS b/NEWS index 584a957f82..033efbc270 100644 --- a/NEWS +++ b/NEWS @@ -333,6 +333,12 @@ Deprecated Functionality tuples. The ConnTuple struct, used by this deprecated Connection constructor, is now deprecated as well. +- The ``zeek::filesystem`` namespace alias is deprecated in favor of using + ``std::filesystem`` directly. Similarly, the ``ghc::filesystem`` submodule stored in + ``auxil/filessytem`` has been removed and the files included from it in the Zeek + installation will no longer be installed. Builds won't warn about the deprecation of + ``zeek::filesystem`` due to limitations of how we can mark deprecations in C++. + Zeek 7.2.0 ========== diff --git a/auxil/filesystem b/auxil/filesystem deleted file mode 160000 index 72a76d774e..0000000000 --- a/auxil/filesystem +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72a76d774e4c7c605141fd6d11c33cc211209ed9 diff --git a/src/MMDB.h b/src/MMDB.h index d9bd4a2815..e491d97cc4 100644 --- a/src/MMDB.h +++ b/src/MMDB.h @@ -2,6 +2,8 @@ #pragma once +#include + #include "zeek/Val.h" namespace zeek { diff --git a/src/ScannedFile.cc b/src/ScannedFile.cc index 00307be9dc..6a6f774d11 100644 --- a/src/ScannedFile.cc +++ b/src/ScannedFile.cc @@ -3,6 +3,7 @@ #include "zeek/ScannedFile.h" #include +#include #include "zeek/DebugLogger.h" #include "zeek/Reporter.h" @@ -22,7 +23,7 @@ ScannedFile::ScannedFile(int arg_include_level, std::string arg_name, bool arg_s canonical_path = canonical_stdin_path; else if ( ! arg_is_canonical ) { std::error_code ec; - auto canon = filesystem::canonical(name, ec); + auto canon = std::filesystem::canonical(name, ec); if ( ec ) zeek::reporter->FatalError("failed to get canonical path of %s: %s", name.data(), ec.message().c_str()); diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index 2a9ed25c7d..b5910e1eac 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -88,7 +89,7 @@ struct LeftoverLog { * Return the "path" (logging framework parlance) of the log without the * directory or file extension. E.g. the "path" of "logs/conn.log" is just "conn". */ - std::string Path() const { return zeek::filesystem::path(filename).stem().string(); } + std::string Path() const { return std::filesystem::path(filename).stem().string(); } /** * Deletes the shadow file and returns whether it succeeded. @@ -102,7 +103,7 @@ struct LeftoverLog { * prefix_basename_with("logs/conn.log", ".shadow") -> logs/.shadow.conn.log" */ static std::string prefix_basename_with(const std::string& path, const std::string& prefix) { - auto fspath = zeek::filesystem::path(path); + auto fspath = std::filesystem::path(path); auto new_filename = prefix + fspath.filename().string(); return (fspath.parent_path() / new_filename).string(); } @@ -440,7 +441,7 @@ bool Ascii::DoInit(const WriterInfo& info, int num_fields, const threading::Fiel } if ( fname.front() != '/' && ! logdir.empty() ) - fname = (zeek::filesystem::path(logdir) / fname).string(); + fname = (std::filesystem::path(logdir) / fname).string(); fname += ext; @@ -679,10 +680,10 @@ static std::vector find_leftover_logs() { // Find any .shadow files within Log::default_logdir or otherwise search in // the current working directory. - auto logdir = zeek::filesystem::current_path(); + auto logdir = std::filesystem::current_path(); if ( ! default_logdir.empty() ) - logdir = zeek::filesystem::absolute(default_logdir); + logdir = std::filesystem::absolute(default_logdir); auto d = opendir(logdir.string().c_str()); struct dirent* dp; diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index 8b80d76eef..8a64c71e86 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -3,6 +3,7 @@ #include "zeek/logging/writers/sqlite/SQLite.h" #include +#include #include #include "zeek/Desc.h" @@ -111,7 +112,7 @@ bool SQLite::DoInit(const WriterInfo& info, int arg_num_fields, const Field* con num_fields = arg_num_fields; fields = arg_fields; - auto fullpath = zeek::filesystem::path(zeek::id::find_const("Log::default_logdir")->ToStdString()); + auto fullpath = std::filesystem::path(zeek::id::find_const("Log::default_logdir")->ToStdString()); fullpath /= info.path; fullpath += ".sqlite"; diff --git a/src/scan.l b/src/scan.l index 2e84ebb47d..051d6e0779 100644 --- a/src/scan.l +++ b/src/scan.l @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -504,7 +505,7 @@ when return TOK_WHEN; // confused by any ZEEKPATH settings. Also, plugin files // containing any relative @loads themselves will work. std::error_code ec; - auto canonical = zeek::filesystem::canonical(input_files[0]); + auto canonical = std::filesystem::canonical(input_files[0]); if ( ec ) zeek::reporter->FatalError("plugin script %s not found: %s", input_files[0], ec.message().c_str()); diff --git a/src/storage/backend/sqlite/SQLite.cc b/src/storage/backend/sqlite/SQLite.cc index aa8422fa86..4d7447b77a 100644 --- a/src/storage/backend/sqlite/SQLite.cc +++ b/src/storage/backend/sqlite/SQLite.cc @@ -2,6 +2,7 @@ #include "zeek/storage/backend/sqlite/SQLite.h" +#include #include #include "zeek/3rdparty/sqlite3.h" @@ -81,7 +82,7 @@ OperationResult SQLite::DoOpen(OpenResultCallback* cb, RecordValPtr options) { RecordValPtr backend_options = options->GetField("sqlite"); StringValPtr path = backend_options->GetField("database_path"); - full_path = zeek::filesystem::path(path->ToStdString()).string(); + full_path = std::filesystem::path(path->ToStdString()).string(); table_name = backend_options->GetField("table_name")->ToStdString(); auto busy_timeout = backend_options->GetField("busy_timeout")->Get(); diff --git a/src/util.cc b/src/util.cc index c575dd7ad3..9e0083ee5a 100644 --- a/src/util.cc +++ b/src/util.cc @@ -25,7 +25,6 @@ #include #include #include -#include #if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2) #include @@ -40,7 +39,9 @@ #include #include +#include #include +#include #include #include @@ -601,7 +602,7 @@ string normalize_path(std::string_view path) { if ( stringPath._Starts_with("//") ) { stringPath.erase(0, 2); } - return zeek::filesystem::path(stringPath).lexically_normal().string(); + return std::filesystem::path(stringPath).lexically_normal().string(); #else if ( path.find("/.") == std::string_view::npos && path.find("//") == std::string_view::npos ) { // no need to normalize anything @@ -691,7 +692,7 @@ string without_zeekpath_component(std::string_view path) { std::string get_exe_path(const std::string& invocation) { if ( invocation.empty() ) return ""; - zeek::filesystem::path invocation_path(invocation); + std::filesystem::path invocation_path(invocation); if ( invocation_path.is_absolute() || invocation_path.root_directory() == "~" ) // Absolute path @@ -706,7 +707,7 @@ std::string get_exe_path(const std::string& invocation) { exit(1); } - return (zeek::filesystem::path(cwd) / invocation_path).string(); + return (std::filesystem::path(cwd) / invocation_path).string(); } auto path = getenv("PATH"); @@ -1719,7 +1720,7 @@ static string find_file_in_path(const string& filename, const string& path, cons if ( filename.empty() ) return {}; - zeek::filesystem::path filepath(filename); + std::filesystem::path filepath(filename); // If file name is an absolute path, searching within *path* is pointless. if ( filepath.is_absolute() ) { @@ -1729,7 +1730,7 @@ static string find_file_in_path(const string& filename, const string& path, cons return {}; } - auto abs_path = (zeek::filesystem::path(path) / filepath).string(); + auto abs_path = (std::filesystem::path(path) / filepath).string(); if ( ! opt_ext.empty() ) { for ( const string& ext : opt_ext ) { @@ -2425,19 +2426,19 @@ TEST_CASE("util filesystem") { #ifdef _MSC_VER // TODO: adapt these tests to Windows paths #else - zeek::filesystem::path path1("/a/b"); + std::filesystem::path path1("/a/b"); CHECK(path1.is_absolute()); CHECK(! path1.is_relative()); CHECK(path1.filename() == "b"); CHECK(path1.parent_path() == "/a"); - zeek::filesystem::path path2("/a//b//conn.log"); + std::filesystem::path path2("/a//b//conn.log"); CHECK(path2.lexically_normal() == "/a/b/conn.log"); - zeek::filesystem::path path3("a//b//"); + std::filesystem::path path3("a//b//"); CHECK(path3.lexically_normal() == "a/b/"); - auto info = zeek::filesystem::space("."); + auto info = std::filesystem::space("."); CHECK(info.capacity > 0); #endif } diff --git a/src/util.h b/src/util.h index 5f8bd0fc24..4fe069d7ae 100644 --- a/src/util.h +++ b/src/util.h @@ -21,6 +21,7 @@ #include #include #include +#include // Remove in v8.1. #include #include #include @@ -79,18 +80,8 @@ extern "C" { #ifdef _MSC_VER #include -#include -namespace zeek { -namespace filesystem = std::filesystem; -} inline constexpr std::string_view path_list_separator = ";"; #else -// Expose ghc::filesystem as zeek::filesystem until we can -// switch to std::filesystem on all platforms. -#include "zeek/3rdparty/ghc/filesystem.hpp" -namespace zeek { -namespace filesystem = ghc::filesystem; -} inline constexpr std::string_view path_list_separator = ":"; #endif @@ -109,6 +100,10 @@ constexpr int UID_POOL_CUSTOM_SCRIPT = 10; // First available custom script leve namespace zeek { +// This alias is deprecated and should be removed in v8.1. There isn't a way to mark +// it so the compiler will flag it. +namespace filesystem = std::filesystem; + class ODesc; class RecordVal;