From 5a302fc4cb213a05da1d8baa27752e7e5962c801 Mon Sep 17 00:00:00 2001 From: Antoine Prouvost Date: Thu, 5 Oct 2023 20:52:41 +0200 Subject: [PATCH] Filesystem library (#2879) * move mamba_fs.hpp * Header cleanup * No util:: dependency in filesystem * Change header names * Use std::replace in filesystem --- libmamba/CMakeLists.txt | 6 ++- libmamba/include/mamba/api/configuration.hpp | 2 +- .../include/mamba/api/configuration_impl.hpp | 10 ++--- libmamba/include/mamba/api/create.hpp | 2 +- libmamba/include/mamba/api/install.hpp | 2 +- libmamba/include/mamba/api/shell.hpp | 2 +- libmamba/include/mamba/api/update.hpp | 2 +- libmamba/include/mamba/core/activation.hpp | 2 +- libmamba/include/mamba/core/context.hpp | 2 +- libmamba/include/mamba/core/env_lockfile.hpp | 4 +- libmamba/include/mamba/core/environment.hpp | 2 +- libmamba/include/mamba/core/fsutil.hpp | 10 ++--- libmamba/include/mamba/core/history.hpp | 3 +- libmamba/include/mamba/core/link.hpp | 2 +- libmamba/include/mamba/core/menuinst.hpp | 3 +- libmamba/include/mamba/core/package_cache.hpp | 3 +- .../include/mamba/core/package_download.hpp | 3 +- .../include/mamba/core/package_handling.hpp | 2 +- libmamba/include/mamba/core/pool.hpp | 1 + libmamba/include/mamba/core/repo.hpp | 11 ++--- libmamba/include/mamba/core/run.hpp | 2 +- libmamba/include/mamba/core/shell_init.hpp | 2 +- libmamba/include/mamba/core/subdirdata.hpp | 4 +- libmamba/include/mamba/core/transaction.hpp | 2 +- .../mamba/core/transaction_context.hpp | 3 +- libmamba/include/mamba/core/util.hpp | 15 ++----- libmamba/include/mamba/core/validate.hpp | 2 +- .../{core/mamba_fs.hpp => fs/filesystem.hpp} | 40 ++++--------------- libmamba/include/mamba/specs/archive.hpp | 2 +- libmamba/src/api/clean.cpp | 2 +- libmamba/src/api/install.cpp | 2 +- libmamba/src/api/shell.cpp | 2 +- libmamba/src/core/curl.cpp | 2 +- libmamba/src/core/env_lockfile.cpp | 2 +- libmamba/src/core/fsutil.cpp | 2 +- libmamba/src/core/package_download.cpp | 2 +- libmamba/src/core/package_paths.cpp | 2 + libmamba/src/core/repo.cpp | 10 ++--- libmamba/src/core/subdirdata.cpp | 3 +- libmamba/src/core/util.cpp | 40 ++++++++++++------- .../{core/mamba_fs.cpp => fs/filesystem.cpp} | 37 ++++++++++++++--- libmamba/src/solv-cpp/repo.cpp | 13 +++--- libmamba/src/solv-cpp/repo.hpp | 8 ++-- libmamba/src/util/url_manip.cpp | 2 +- libmamba/tests/libmamba_lock/lock.cpp | 8 ++-- .../src/core/test_environments_manager.cpp | 2 +- libmamba/tests/src/core/test_filesystem.cpp | 2 +- libmamba/tests/src/core/test_history.cpp | 2 +- libmamba/tests/src/core/test_lockfile.cpp | 2 +- .../src/core/test_satisfiability_error.cpp | 3 +- libmamba/tests/src/core/test_util.cpp | 2 +- libmamba/tests/src/specs/test_archive.cpp | 1 + libmamba/tests/src/test_data.hpp | 2 +- libmamba/tests/src/util/test_string.cpp | 2 +- libmamba/tests/src/util/test_url_manip.cpp | 9 +++-- micromamba/src/completer.cpp | 9 +++-- micromamba/src/constructor.hpp | 6 +-- micromamba/src/env.cpp | 6 +-- micromamba/src/login.cpp | 16 ++++---- 59 files changed, 184 insertions(+), 163 deletions(-) rename libmamba/include/mamba/{core/mamba_fs.hpp => fs/filesystem.hpp} (98%) rename libmamba/src/{core/mamba_fs.cpp => fs/filesystem.cpp} (54%) diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index bcd1b2eac6..584d1e4f71 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -118,6 +118,8 @@ endforeach() set(LIBMAMBA_SOURCES longpath.manifest ${LIBMAMBA_SOURCE_DIR}/version.cpp + # Filesystem library + ${LIBMAMBA_SOURCE_DIR}/fs/filesystem.cpp # C++ utility library ${LIBMAMBA_SOURCE_DIR}/util/string.cpp ${LIBMAMBA_SOURCE_DIR}/util/path_manip.cpp @@ -155,7 +157,6 @@ set(LIBMAMBA_SOURCES ${LIBMAMBA_SOURCE_DIR}/core/transaction_context.cpp ${LIBMAMBA_SOURCE_DIR}/core/link.cpp ${LIBMAMBA_SOURCE_DIR}/core/history.cpp - ${LIBMAMBA_SOURCE_DIR}/core/mamba_fs.cpp ${LIBMAMBA_SOURCE_DIR}/core/match_spec.cpp ${LIBMAMBA_SOURCE_DIR}/core/menuinst.cpp ${LIBMAMBA_SOURCE_DIR}/core/output.cpp @@ -209,6 +210,8 @@ endforeach() set(LIBMAMBA_PUBLIC_HEADERS ${LIBMAMBA_INCLUDE_DIR}/mamba/version.hpp + # Filesystem library + ${LIBMAMBA_INCLUDE_DIR}/mamba/fs/filesystem.hpp # Utility library ${LIBMAMBA_INCLUDE_DIR}/mamba/util/json.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/util/deprecation.hpp @@ -248,7 +251,6 @@ set(LIBMAMBA_PUBLIC_HEADERS ${LIBMAMBA_INCLUDE_DIR}/mamba/core/satisfiability_error.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/history.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/link.hpp - ${LIBMAMBA_INCLUDE_DIR}/mamba/core/mamba_fs.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/match_spec.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/menuinst.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/output.hpp diff --git a/libmamba/include/mamba/api/configuration.hpp b/libmamba/include/mamba/api/configuration.hpp index a2a88da3ea..c0118854ab 100644 --- a/libmamba/include/mamba/api/configuration.hpp +++ b/libmamba/include/mamba/api/configuration.hpp @@ -15,8 +15,8 @@ #include "mamba/api/constants.hpp" #include "mamba/core/context.hpp" #include "mamba/core/environment.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba diff --git a/libmamba/include/mamba/api/configuration_impl.hpp b/libmamba/include/mamba/api/configuration_impl.hpp index 0f94b76671..ddf1c5e082 100644 --- a/libmamba/include/mamba/api/configuration_impl.hpp +++ b/libmamba/include/mamba/api/configuration_impl.hpp @@ -9,7 +9,7 @@ #include "mamba/core/common_types.hpp" #include "mamba/core/context.hpp" -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { @@ -304,21 +304,21 @@ namespace YAML }; template <> - struct convert + struct convert { - static Node encode(const fs::u8path& rhs) + static Node encode(const mamba::fs::u8path& rhs) { return Node(rhs.string()); } - static bool decode(const Node& node, fs::u8path& rhs) + static bool decode(const Node& node, mamba::fs::u8path& rhs) { if (!node.IsScalar()) { return false; } - rhs = fs::u8path(node.as()); + rhs = mamba::fs::u8path(node.as()); return true; } }; diff --git a/libmamba/include/mamba/api/create.hpp b/libmamba/include/mamba/api/create.hpp index 5c0bacba03..49c3c3abf6 100644 --- a/libmamba/include/mamba/api/create.hpp +++ b/libmamba/include/mamba/api/create.hpp @@ -9,7 +9,7 @@ #include -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/include/mamba/api/install.hpp b/libmamba/include/mamba/api/install.hpp index 68777b0e49..451930f36a 100644 --- a/libmamba/include/mamba/api/install.hpp +++ b/libmamba/include/mamba/api/install.hpp @@ -15,12 +15,12 @@ #include #include "mamba/core/context.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/package_cache.hpp" #include "mamba/core/package_info.hpp" #include "mamba/core/pool.hpp" #include "mamba/core/repo.hpp" #include "mamba/core/solver.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/include/mamba/api/shell.hpp b/libmamba/include/mamba/api/shell.hpp index 5b3172552a..8e02dcef0c 100644 --- a/libmamba/include/mamba/api/shell.hpp +++ b/libmamba/include/mamba/api/shell.hpp @@ -10,8 +10,8 @@ #include #include -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/palette.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/include/mamba/api/update.hpp b/libmamba/include/mamba/api/update.hpp index b3d332b74a..ee45122057 100644 --- a/libmamba/include/mamba/api/update.hpp +++ b/libmamba/include/mamba/api/update.hpp @@ -10,8 +10,8 @@ #include #include -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/query.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba diff --git a/libmamba/include/mamba/core/activation.hpp b/libmamba/include/mamba/core/activation.hpp index ea175b73b0..8c09bd3134 100644 --- a/libmamba/include/mamba/core/activation.hpp +++ b/libmamba/include/mamba/core/activation.hpp @@ -12,7 +12,7 @@ #include #include -#include "mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" // TODO write a map that keeps insertion order diff --git a/libmamba/include/mamba/core/context.hpp b/libmamba/include/mamba/core/context.hpp index cf4e9b2416..e6e83829cb 100644 --- a/libmamba/include/mamba/core/context.hpp +++ b/libmamba/include/mamba/core/context.hpp @@ -13,9 +13,9 @@ #include #include "mamba/core/common_types.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/palette.hpp" #include "mamba/core/tasksync.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/specs/authentification_info.hpp" #include "mamba/specs/platform.hpp" #include "mamba/version.hpp" diff --git a/libmamba/include/mamba/core/env_lockfile.hpp b/libmamba/include/mamba/core/env_lockfile.hpp index f41f4d4101..b200f30f5b 100644 --- a/libmamba/include/mamba/core/env_lockfile.hpp +++ b/libmamba/include/mamba/core/env_lockfile.hpp @@ -15,6 +15,8 @@ #include +#include "mamba/fs/filesystem.hpp" + #include "error_handling.hpp" #include "fsutil.hpp" #include "package_info.hpp" @@ -111,7 +113,7 @@ namespace mamba /// Read an environment lock YAML file and returns it's structured content or an error if /// failed. tl::expected - read_environment_lockfile(ChannelContext& channel_context, const fs::u8path& lockfile_location); + read_environment_lockfile(ChannelContext& channel_context, const mamba::fs::u8path& lockfile_location); /// Returns `true` if the filename matches names of files which should be interpreted as conda diff --git a/libmamba/include/mamba/core/environment.hpp b/libmamba/include/mamba/core/environment.hpp index 850dc273b1..f41e779e0f 100644 --- a/libmamba/include/mamba/core/environment.hpp +++ b/libmamba/include/mamba/core/environment.hpp @@ -13,7 +13,7 @@ #include #include -#include "mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" #ifdef _WIN32 #include diff --git a/libmamba/include/mamba/core/fsutil.hpp b/libmamba/include/mamba/core/fsutil.hpp index 940f8734ef..51df188793 100644 --- a/libmamba/include/mamba/core/fsutil.hpp +++ b/libmamba/include/mamba/core/fsutil.hpp @@ -9,13 +9,13 @@ #include -namespace fs -{ - class u8path; -} - namespace mamba { + namespace fs + { + class u8path; + } + namespace path { bool starts_with_home(const fs::u8path& p); diff --git a/libmamba/include/mamba/core/history.hpp b/libmamba/include/mamba/core/history.hpp index bcbce0d116..b205a9769b 100644 --- a/libmamba/include/mamba/core/history.hpp +++ b/libmamba/include/mamba/core/history.hpp @@ -12,7 +12,8 @@ #include #include -#include "mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" + #include "match_spec.hpp" namespace mamba diff --git a/libmamba/include/mamba/core/link.hpp b/libmamba/include/mamba/core/link.hpp index b7f00b091e..201ca0f440 100644 --- a/libmamba/include/mamba/core/link.hpp +++ b/libmamba/include/mamba/core/link.hpp @@ -13,9 +13,9 @@ #include #include +#include "mamba/fs/filesystem.hpp" #include "mamba/util/build.hpp" -#include "mamba_fs.hpp" #include "match_spec.hpp" #include "package_paths.hpp" #include "transaction.hpp" diff --git a/libmamba/include/mamba/core/menuinst.hpp b/libmamba/include/mamba/core/menuinst.hpp index f8bb1d11e9..c91ebc16fe 100644 --- a/libmamba/include/mamba/core/menuinst.hpp +++ b/libmamba/include/mamba/core/menuinst.hpp @@ -1,4 +1,5 @@ -#include "mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" + #include "transaction_context.hpp" namespace mamba diff --git a/libmamba/include/mamba/core/package_cache.hpp b/libmamba/include/mamba/core/package_cache.hpp index 4badba030c..1aaafd4178 100644 --- a/libmamba/include/mamba/core/package_cache.hpp +++ b/libmamba/include/mamba/core/package_cache.hpp @@ -11,8 +11,9 @@ #include #include +#include "mamba/fs/filesystem.hpp" + #include "fsutil.hpp" -#include "mamba_fs.hpp" #include "package_info.hpp" #define PACKAGE_CACHE_MAGIC_FILE "urls.txt" diff --git a/libmamba/include/mamba/core/package_download.hpp b/libmamba/include/mamba/core/package_download.hpp index 107c5169ab..a6008a2826 100644 --- a/libmamba/include/mamba/core/package_download.hpp +++ b/libmamba/include/mamba/core/package_download.hpp @@ -15,8 +15,9 @@ #include #include +#include "mamba/fs/filesystem.hpp" + #include "fetch.hpp" -#include "mamba_fs.hpp" #include "package_cache.hpp" #include "progress_bar.hpp" #include "tasksync.hpp" diff --git a/libmamba/include/mamba/core/package_handling.hpp b/libmamba/include/mamba/core/package_handling.hpp index b56c42098d..c57c9bb2fb 100644 --- a/libmamba/include/mamba/core/package_handling.hpp +++ b/libmamba/include/mamba/core/package_handling.hpp @@ -11,7 +11,7 @@ #include #include -#include "mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/include/mamba/core/pool.hpp b/libmamba/include/mamba/core/pool.hpp index 5e2346e0a4..702a73725e 100644 --- a/libmamba/include/mamba/core/pool.hpp +++ b/libmamba/include/mamba/core/pool.hpp @@ -18,6 +18,7 @@ namespace mamba { class MatchSpec; class ChannelContext; + class Context; namespace solv { diff --git a/libmamba/include/mamba/core/repo.hpp b/libmamba/include/mamba/core/repo.hpp index ea3d78f5f7..3f611bc23f 100644 --- a/libmamba/include/mamba/core/repo.hpp +++ b/libmamba/include/mamba/core/repo.hpp @@ -24,13 +24,14 @@ extern "C" typedef struct s_Repodata Repodata; } -namespace fs -{ - class u8path; -} - namespace mamba { + + namespace fs + { + class u8path; + } + class PackageInfo; class PrefixData; diff --git a/libmamba/include/mamba/core/run.hpp b/libmamba/include/mamba/core/run.hpp index 4e47009e5c..207acd7d34 100644 --- a/libmamba/include/mamba/core/run.hpp +++ b/libmamba/include/mamba/core/run.hpp @@ -9,8 +9,8 @@ #include -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/include/mamba/core/shell_init.hpp b/libmamba/include/mamba/core/shell_init.hpp index ecf088a890..c07c2bba09 100644 --- a/libmamba/include/mamba/core/shell_init.hpp +++ b/libmamba/include/mamba/core/shell_init.hpp @@ -10,7 +10,7 @@ #include #include -#include "mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" extern const char data_micromamba_sh[]; extern const char data_micromamba_csh[]; diff --git a/libmamba/include/mamba/core/subdirdata.hpp b/libmamba/include/mamba/core/subdirdata.hpp index 2e8639dfdd..59eb305338 100644 --- a/libmamba/include/mamba/core/subdirdata.hpp +++ b/libmamba/include/mamba/core/subdirdata.hpp @@ -8,7 +8,6 @@ #define MAMBA_CORE_SUBDIRDATA_HPP #include -#include #include #include @@ -17,11 +16,12 @@ #include "mamba/core/context.hpp" #include "mamba/core/download.hpp" #include "mamba/core/error_handling.hpp" -#include "mamba/core/mamba_fs.hpp" +#include "mamba/core/fetch.hpp" #include "mamba/core/package_cache.hpp" #include "mamba/core/pool.hpp" #include "mamba/core/repo.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" #include "package_handling.hpp" diff --git a/libmamba/include/mamba/core/transaction.hpp b/libmamba/include/mamba/core/transaction.hpp index cab63b261c..0aee7a207e 100644 --- a/libmamba/include/mamba/core/transaction.hpp +++ b/libmamba/include/mamba/core/transaction.hpp @@ -12,8 +12,8 @@ #include #include "mamba/api/install.hpp" +#include "mamba/fs/filesystem.hpp" -#include "mamba_fs.hpp" #include "match_spec.hpp" #include "package_cache.hpp" #include "package_info.hpp" diff --git a/libmamba/include/mamba/core/transaction_context.hpp b/libmamba/include/mamba/core/transaction_context.hpp index b2b45a2a72..66891d5891 100644 --- a/libmamba/include/mamba/core/transaction_context.hpp +++ b/libmamba/include/mamba/core/transaction_context.hpp @@ -11,8 +11,9 @@ #include +#include "mamba/fs/filesystem.hpp" + #include "context.hpp" -#include "mamba_fs.hpp" #include "match_spec.hpp" #include "util.hpp" diff --git a/libmamba/include/mamba/core/util.hpp b/libmamba/include/mamba/core/util.hpp index 1281a367be..2427636bfc 100644 --- a/libmamba/include/mamba/core/util.hpp +++ b/libmamba/include/mamba/core/util.hpp @@ -7,28 +7,19 @@ #ifndef MAMBA_CORE_UTIL_HPP #define MAMBA_CORE_UTIL_HPP -#include #include -#include +#include +#include #include -#include #include #include -#include #include -#include - #include "mamba/core/error_handling.hpp" -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" -#include "nlohmann/json.hpp" #include "tl/expected.hpp" -#if defined(__PPC64__) || defined(__ppc64__) || defined(_ARCH_PPC64) -#include -#endif - #define MAMBA_EMPTY_SHA "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; namespace mamba diff --git a/libmamba/include/mamba/core/validate.hpp b/libmamba/include/mamba/core/validate.hpp index 3787ad1832..d9030c16d1 100644 --- a/libmamba/include/mamba/core/validate.hpp +++ b/libmamba/include/mamba/core/validate.hpp @@ -14,9 +14,9 @@ #include -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/timeref.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba::validation { diff --git a/libmamba/include/mamba/core/mamba_fs.hpp b/libmamba/include/mamba/fs/filesystem.hpp similarity index 98% rename from libmamba/include/mamba/core/mamba_fs.hpp rename to libmamba/include/mamba/fs/filesystem.hpp index 65c515c890..6449eaff5d 100644 --- a/libmamba/include/mamba/core/mamba_fs.hpp +++ b/libmamba/include/mamba/fs/filesystem.hpp @@ -4,27 +4,14 @@ // // The full license is in the file LICENSE, distributed with this software. -#ifndef MAMBA_CORE_FS_HPP -#define MAMBA_CORE_FS_HPP +#ifndef MAMBA_CORE_FS_FILESYSTEM_HPP +#define MAMBA_CORE_FS_FILESYSTEM_HPP #include -#include #include #include -#if !defined(_WIN32) -#include -#include - -// We can use the presence of UTIME_OMIT to detect platforms that provide -// utimensat. -#if defined(UTIME_OMIT) -#define USE_UTIMENSAT -#endif -#endif - - //---- RATIONAL: Why do we wrap standard filesystem here? ---- // 1. This codebase relies on `std::string` and `const char*` to denote UTF-8 encoded text. // However `std::filesystem::path` constructors cannot assume that `std::string` is in @@ -79,7 +66,7 @@ // (at least until the stnadard library provide better options). -namespace fs +namespace mamba::fs { // sentinel argument for indicating the current time to last_write_time class now @@ -1151,18 +1138,7 @@ namespace fs } // void last_write_time(const path& p, now _, error_code& ec) noexcept; - inline void last_write_time(const u8path& path, now, std::error_code& ec) noexcept - { -#if defined(USE_UTIMENSAT) - if (utimensat(AT_FDCWD, path.string().c_str(), NULL, 0) == -1) - { - ec = std::error_code(errno, std::generic_category()); - } -#else - auto new_time = fs::file_time_type::clock::now(); - std::filesystem::last_write_time(path, new_time, ec); -#endif - } + void last_write_time(const u8path& path, now, std::error_code& ec) noexcept; // void last_write_time(const path& p, now _); inline void last_write_time(const u8path& path, now sentinel) @@ -1355,9 +1331,9 @@ namespace fs } template <> -struct std::hash<::fs::u8path> +struct std::hash<::mamba::fs::u8path> { - std::size_t operator()(const ::fs::u8path& path) const noexcept + std::size_t operator()(const ::mamba::fs::u8path& path) const noexcept { return std::filesystem::hash_value(path.std_path() ); // TODO: once we stop using gcc < 12 we can properly use @@ -1366,7 +1342,7 @@ struct std::hash<::fs::u8path> }; template <> -struct fmt::formatter<::fs::u8path> +struct fmt::formatter<::mamba::fs::u8path> { constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { @@ -1379,7 +1355,7 @@ struct fmt::formatter<::fs::u8path> } template - auto format(const ::fs::u8path& path, FormatContext& ctx) + auto format(const ::mamba::fs::u8path& path, FormatContext& ctx) { return fmt::format_to(ctx.out(), "'{}'", path.string()); } diff --git a/libmamba/include/mamba/specs/archive.hpp b/libmamba/include/mamba/specs/archive.hpp index 3632d89dde..2af0d47669 100644 --- a/libmamba/include/mamba/specs/archive.hpp +++ b/libmamba/include/mamba/specs/archive.hpp @@ -11,7 +11,7 @@ #include #include -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba::specs { diff --git a/libmamba/src/api/clean.cpp b/libmamba/src/api/clean.cpp index f6fcf1fe67..785f339f8a 100644 --- a/libmamba/src/api/clean.cpp +++ b/libmamba/src/api/clean.cpp @@ -9,9 +9,9 @@ #include "mamba/api/clean.hpp" #include "mamba/api/configuration.hpp" #include "mamba/core/context.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/package_cache.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" #include "../core/progress_bar_impl.hpp" diff --git a/libmamba/src/api/install.cpp b/libmamba/src/api/install.cpp index 3605ba95a2..13f17be408 100644 --- a/libmamba/src/api/install.cpp +++ b/libmamba/src/api/install.cpp @@ -20,12 +20,12 @@ #include "mamba/core/env_lockfile.hpp" #include "mamba/core/environments_manager.hpp" #include "mamba/core/fetch.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" #include "mamba/core/package_cache.hpp" #include "mamba/core/pinning.hpp" #include "mamba/core/transaction.hpp" #include "mamba/core/virtual_packages.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" namespace mamba diff --git a/libmamba/src/api/shell.cpp b/libmamba/src/api/shell.cpp index 95a5a14db3..a48c48e7d0 100644 --- a/libmamba/src/api/shell.cpp +++ b/libmamba/src/api/shell.cpp @@ -12,8 +12,8 @@ #include "mamba/core/activation.hpp" #include "mamba/core/context.hpp" #include "mamba/core/environment.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/shell_init.hpp" +#include "mamba/fs/filesystem.hpp" #ifdef _WIN32 #include "mamba/core/util_os.hpp" diff --git a/libmamba/src/core/curl.cpp b/libmamba/src/core/curl.cpp index 2dbaa07504..814b7e99d0 100644 --- a/libmamba/src/core/curl.cpp +++ b/libmamba/src/core/curl.cpp @@ -10,8 +10,8 @@ #include "mamba/core/context.hpp" #include "mamba/core/environment.hpp" // for NETRC env var -#include "mamba/core/mamba_fs.hpp" // for fs::exists #include "mamba/core/util.hpp" // for hide_secrets +#include "mamba/fs/filesystem.hpp" // for fs::exists #include "curl.hpp" diff --git a/libmamba/src/core/env_lockfile.cpp b/libmamba/src/core/env_lockfile.cpp index 98dd8d5669..a98edaf328 100644 --- a/libmamba/src/core/env_lockfile.cpp +++ b/libmamba/src/core/env_lockfile.cpp @@ -8,8 +8,8 @@ #include #include "mamba/core/env_lockfile.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/match_spec.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" namespace mamba diff --git a/libmamba/src/core/fsutil.cpp b/libmamba/src/core/fsutil.cpp index 347cfc987e..3db1d176cf 100644 --- a/libmamba/src/core/fsutil.cpp +++ b/libmamba/src/core/fsutil.cpp @@ -10,10 +10,10 @@ #include "mamba/core/environment.hpp" #include "mamba/core/fsutil.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" #include "mamba/core/util.hpp" #include "mamba/core/util_scope.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" namespace mamba::path diff --git a/libmamba/src/core/package_download.cpp b/libmamba/src/core/package_download.cpp index 51371cd813..689b6f597c 100644 --- a/libmamba/src/core/package_download.cpp +++ b/libmamba/src/core/package_download.cpp @@ -15,13 +15,13 @@ #include "mamba/core/context.hpp" #include "mamba/core/execution.hpp" #include "mamba/core/fetch.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" #include "mamba/core/package_cache.hpp" #include "mamba/core/package_download.hpp" #include "mamba/core/package_handling.hpp" #include "mamba/core/progress_bar.hpp" #include "mamba/core/thread_utils.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" #include "progress_bar_impl.hpp" diff --git a/libmamba/src/core/package_paths.cpp b/libmamba/src/core/package_paths.cpp index 9326dc41b3..c4c11fd76d 100644 --- a/libmamba/src/core/package_paths.cpp +++ b/libmamba/src/core/package_paths.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include "mamba/core/package_paths.hpp" #include "mamba/util/string.hpp" diff --git a/libmamba/src/core/repo.cpp b/libmamba/src/core/repo.cpp index e9bb410d17..81ddf9e6a2 100644 --- a/libmamba/src/core/repo.cpp +++ b/libmamba/src/core/repo.cpp @@ -23,13 +23,13 @@ extern "C" // Incomplete header } #include "mamba/core/context.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" #include "mamba/core/package_info.hpp" #include "mamba/core/pool.hpp" #include "mamba/core/prefix_data.hpp" #include "mamba/core/repo.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/build.hpp" #include "mamba/util/string.hpp" #include "mamba/util/url_manip.hpp" @@ -117,7 +117,7 @@ namespace mamba for (const auto& dep : pkg.depends) { // TODO pool's matchspec2id - solv::DependencyId const dep_id = pool_conda_matchspec(pool, dep.c_str()); + const solv::DependencyId dep_id = pool_conda_matchspec(pool, dep.c_str()); assert(dep_id); solv.add_dependency(dep_id); } @@ -125,7 +125,7 @@ namespace mamba for (const auto& cons : pkg.constrains) { // TODO pool's matchspec2id - solv::DependencyId const dep_id = pool_conda_matchspec(pool, cons.c_str()); + const solv::DependencyId dep_id = pool_conda_matchspec(pool, cons.c_str()); assert(dep_id); solv.add_constraint(dep_id); } @@ -432,8 +432,8 @@ namespace mamba void MRepo::add_pip_as_python_dependency() { - solv::DependencyId const python_id = pool_conda_matchspec(m_pool, "python"); - solv::DependencyId const pip_id = pool_conda_matchspec(m_pool, "pip"); + const solv::DependencyId python_id = pool_conda_matchspec(m_pool, "python"); + const solv::DependencyId pip_id = pool_conda_matchspec(m_pool, "pip"); srepo(*this).for_each_solvable( [&](solv::ObjSolvableView s) { diff --git a/libmamba/src/core/subdirdata.cpp b/libmamba/src/core/subdirdata.cpp index 353a0dcc4c..b22be7463b 100644 --- a/libmamba/src/core/subdirdata.cpp +++ b/libmamba/src/core/subdirdata.cpp @@ -4,13 +4,14 @@ // // The full license is in the file LICENSE, distributed with this software. +#include #include -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" #include "mamba/core/package_cache.hpp" #include "mamba/core/subdirdata.hpp" #include "mamba/core/thread_utils.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/json.hpp" #include "mamba/util/string.hpp" #include "mamba/util/url_manip.hpp" diff --git a/libmamba/src/core/util.cpp b/libmamba/src/core/util.cpp index 6f648687c6..974a326937 100644 --- a/libmamba/src/core/util.cpp +++ b/libmamba/src/core/util.cpp @@ -4,10 +4,30 @@ // // The full license is in the file LICENSE, distributed with this software. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#if defined(__APPLE__) || defined(__linux__) -#include +#include + +#if defined(__PPC64__) || defined(__ppc64__) || defined(_ARCH_PPC64) +#include +#endif +#if defined(__APPLE__) || defined(__linux__) #include #include #include @@ -26,24 +46,15 @@ extern "C" #include #include } - #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include #include +#include #include "mamba/core/context.hpp" #include "mamba/core/environment.hpp" +#include "mamba/core/error_handling.hpp" #include "mamba/core/execution.hpp" #include "mamba/core/invoke.hpp" #include "mamba/core/output.hpp" @@ -52,6 +63,7 @@ extern "C" #include "mamba/core/util.hpp" #include "mamba/core/util_os.hpp" #include "mamba/core/util_random.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/build.hpp" #include "mamba/util/compare.hpp" #include "mamba/util/string.hpp" diff --git a/libmamba/src/core/mamba_fs.cpp b/libmamba/src/fs/filesystem.cpp similarity index 54% rename from libmamba/src/core/mamba_fs.cpp rename to libmamba/src/fs/filesystem.cpp index 8362fece8d..558b09471a 100644 --- a/libmamba/src/core/mamba_fs.cpp +++ b/libmamba/src/fs/filesystem.cpp @@ -4,13 +4,25 @@ // // The full license is in the file LICENSE, distributed with this software. +#ifdef _WIN32 +#include +#endif #include #include -#include "mamba/core/mamba_fs.hpp" -#include "mamba/util/string.hpp" +#ifndef _WIN32 +#include +#include +// We can use the presence of UTIME_OMIT to detect platforms that provide +// utimensat. +#if defined(UTIME_OMIT) +#define USE_UTIMENSAT +#endif +#endif -namespace fs +#include "mamba/fs/filesystem.hpp" + +namespace mamba::fs { #if defined(_WIN32) @@ -18,9 +30,9 @@ namespace fs std::filesystem::path normalized_separators(std::filesystem::path path) { auto native_string = path.native(); - static constexpr auto platform_separator = L"\\"; - static constexpr auto other_separator = L"/"; - mamba::util::replace_all(native_string, other_separator, platform_separator); + static constexpr wchar_t platform_sep = L'\\'; + static constexpr wchar_t other_sep = L'/'; + std::replace(native_string.begin(), native_string.end(), other_sep, platform_sep); path = std::move(native_string); return path; } @@ -45,4 +57,17 @@ namespace fs #else #error UTF8 functions implementation is specific to C++17, using another version requires a different implementation. #endif + + void last_write_time(const u8path& path, now, std::error_code& ec) noexcept + { +#if defined(USE_UTIMENSAT) + if (utimensat(AT_FDCWD, path.string().c_str(), NULL, 0) == -1) + { + ec = std::error_code(errno, std::generic_category()); + } +#else + auto new_time = fs::file_time_type::clock::now(); + std::filesystem::last_write_time(path, new_time, ec); +#endif + } } diff --git a/libmamba/src/solv-cpp/repo.cpp b/libmamba/src/solv-cpp/repo.cpp index b15f8ef723..0e539617a8 100644 --- a/libmamba/src/solv-cpp/repo.cpp +++ b/libmamba/src/solv-cpp/repo.cpp @@ -26,7 +26,7 @@ extern "C" // Incomplete header in libsolv 0.7.23 #include } -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" #include "solv-cpp/repo.hpp" namespace mamba::solv @@ -110,7 +110,7 @@ namespace mamba::solv * * @param path must hae filesystem default encoding. */ - static auto open(const fs::u8path& path, const char* mode) -> CFile; + static auto open(const mamba::fs::u8path& path, const char* mode) -> CFile; /** * The destructor will flush and close the file descriptor. @@ -153,7 +153,7 @@ namespace mamba::solv } } - auto CFile::open(const fs::u8path& path, const char* mode) -> CFile + auto CFile::open(const mamba::fs::u8path& path, const char* mode) -> CFile { #ifdef _WIN32 // Mode MUST be an ASCII string @@ -193,7 +193,7 @@ namespace mamba::solv } } - void ObjRepoViewConst::write(const fs::u8path& solv_file) const + void ObjRepoViewConst::write(const mamba::fs::u8path& solv_file) const { auto file = CFile::open(solv_file, "wb"); const auto write_res = ::repo_write(const_cast<::Repo*>(raw()), file.raw()); @@ -226,7 +226,7 @@ namespace mamba::solv ::repo_empty(raw(), static_cast(reuse_ids)); } - void ObjRepoView::read(const fs::u8path& solv_file) const + void ObjRepoView::read(const mamba::fs::u8path& solv_file) const { auto file = CFile::open(solv_file, "rb"); const auto read_res = ::repo_add_solv(raw(), file.raw(), 0); @@ -243,7 +243,8 @@ namespace mamba::solv } } - void ObjRepoView::legacy_read_conda_repodata(const fs::u8path& repodata_file, int flags) const + void + ObjRepoView::legacy_read_conda_repodata(const mamba::fs::u8path& repodata_file, int flags) const { auto file = CFile::open(repodata_file, "rb"); const auto res = ::repo_add_conda(raw(), file.raw(), flags); diff --git a/libmamba/src/solv-cpp/repo.hpp b/libmamba/src/solv-cpp/repo.hpp index 8c6f510b34..e0498f8c1f 100644 --- a/libmamba/src/solv-cpp/repo.hpp +++ b/libmamba/src/solv-cpp/repo.hpp @@ -17,7 +17,7 @@ #include "solv-cpp/ids.hpp" #include "solv-cpp/solvable.hpp" -namespace fs +namespace mamba::fs { class u8path; } @@ -114,7 +114,7 @@ namespace mamba::solv * @warning This is a binary file that is not portable and may not even remain valid among * different libsolv build, let alone versions. */ - void write(const fs::u8path& solv_file) const; + void write(const mamba::fs::u8path& solv_file) const; private: @@ -224,7 +224,7 @@ namespace mamba::solv * @param solv_file A standard path with system encoding. * @see ObjRepoViewConst::write */ - void read(const fs::u8path& solv_file) const; + void read(const mamba::fs::u8path& solv_file) const; /** * Read repository information from a conda repodata.json. @@ -234,7 +234,7 @@ namespace mamba::solv * added through the API. * @param repodata_file A standard path with system encoding. */ - void legacy_read_conda_repodata(const fs::u8path& repodata_file, int flags = 0) const; + void legacy_read_conda_repodata(const mamba::fs::u8path& repodata_file, int flags = 0) const; /** Add an empty solvable to the repository. */ auto add_solvable() const -> std::pair; diff --git a/libmamba/src/util/url_manip.cpp b/libmamba/src/util/url_manip.cpp index b0d80b2013..a1b256828d 100644 --- a/libmamba/src/util/url_manip.cpp +++ b/libmamba/src/util/url_manip.cpp @@ -15,7 +15,7 @@ #include #include -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/build.hpp" #include "mamba/util/path_manip.hpp" #include "mamba/util/string.hpp" diff --git a/libmamba/tests/libmamba_lock/lock.cpp b/libmamba/tests/libmamba_lock/lock.cpp index a6c7269bea..1a63363d4d 100644 --- a/libmamba/tests/libmamba_lock/lock.cpp +++ b/libmamba/tests/libmamba_lock/lock.cpp @@ -1,10 +1,10 @@ #include #include "mamba/core/context.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/output.hpp" #include "mamba/core/thread_utils.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" #if defined(__APPLE__) || defined(__linux__) #include @@ -12,7 +12,7 @@ #endif bool -is_locked(const fs::u8path& path) +is_locked(const mamba::fs::u8path& path) { #ifdef _WIN32 return mamba::LockFile::is_locked(path); @@ -34,7 +34,7 @@ main(int argc, char** argv) } }; CLI::App app{}; - fs::u8path path; + mamba::fs::u8path path; std::size_t timeout = 1; CLI::App* lock_com = app.add_subcommand("lock", "Lock a path"); @@ -66,7 +66,7 @@ main(int argc, char** argv) CLI::App* is_locked_com = app.add_subcommand("is-locked", "Check if a path is locked"); is_locked_com->add_option("path", path, "Path to check"); - is_locked_com->callback([&]() { std::cout << (fs::exists(path) && is_locked(path)); }); + is_locked_com->callback([&]() { std::cout << (mamba::fs::exists(path) && is_locked(path)); }); try { diff --git a/libmamba/tests/src/core/test_environments_manager.cpp b/libmamba/tests/src/core/test_environments_manager.cpp index c296151048..d0b384d7f8 100644 --- a/libmamba/tests/src/core/test_environments_manager.cpp +++ b/libmamba/tests/src/core/test_environments_manager.cpp @@ -9,7 +9,7 @@ #include "mamba/core/context.hpp" #include "mamba/core/environment.hpp" #include "mamba/core/environments_manager.hpp" -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" #include "mambatests.hpp" diff --git a/libmamba/tests/src/core/test_filesystem.cpp b/libmamba/tests/src/core/test_filesystem.cpp index 90dcb30dbb..511c0e3d69 100644 --- a/libmamba/tests/src/core/test_filesystem.cpp +++ b/libmamba/tests/src/core/test_filesystem.cpp @@ -8,9 +8,9 @@ #include -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/util.hpp" #include "mamba/core/util_scope.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/tests/src/core/test_history.cpp b/libmamba/tests/src/core/test_history.cpp index cd2a7fbf79..557696ea3f 100644 --- a/libmamba/tests/src/core/test_history.cpp +++ b/libmamba/tests/src/core/test_history.cpp @@ -4,6 +4,7 @@ // // The full license is in the file LICENSE, distributed with this software. +#include #include #include #include @@ -19,7 +20,6 @@ #endif #include "mamba/core/channel.hpp" -#include "mamba/core/context.hpp" #include "mamba/core/history.hpp" #include "test_data.hpp" diff --git a/libmamba/tests/src/core/test_lockfile.cpp b/libmamba/tests/src/core/test_lockfile.cpp index 78aeba56a9..0b7d66acde 100644 --- a/libmamba/tests/src/core/test_lockfile.cpp +++ b/libmamba/tests/src/core/test_lockfile.cpp @@ -11,8 +11,8 @@ #include #include "mamba/core/context.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" #include "spdlog/spdlog.h" diff --git a/libmamba/tests/src/core/test_satisfiability_error.cpp b/libmamba/tests/src/core/test_satisfiability_error.cpp index 2420ca12a8..4d3864d05b 100644 --- a/libmamba/tests/src/core/test_satisfiability_error.cpp +++ b/libmamba/tests/src/core/test_satisfiability_error.cpp @@ -15,8 +15,6 @@ #include #include "mamba/core/channel.hpp" -#include "mamba/core/download.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/package_info.hpp" #include "mamba/core/pool.hpp" #include "mamba/core/prefix_data.hpp" @@ -26,6 +24,7 @@ #include "mamba/core/subdirdata.hpp" #include "mamba/core/util.hpp" #include "mamba/core/util_random.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" #include "mambatests.hpp" diff --git a/libmamba/tests/src/core/test_util.cpp b/libmamba/tests/src/core/test_util.cpp index 1fe65158a5..58e5a59597 100644 --- a/libmamba/tests/src/core/test_util.cpp +++ b/libmamba/tests/src/core/test_util.cpp @@ -10,10 +10,10 @@ #include "mamba/core/environment.hpp" #include "mamba/core/execution.hpp" #include "mamba/core/fsutil.hpp" -#include "mamba/core/mamba_fs.hpp" #include "mamba/core/util.hpp" #include "mamba/core/util_random.hpp" #include "mamba/core/util_scope.hpp" +#include "mamba/fs/filesystem.hpp" #include "mambatests.hpp" diff --git a/libmamba/tests/src/specs/test_archive.cpp b/libmamba/tests/src/specs/test_archive.cpp index 2bb63b4b3c..81233b4d97 100644 --- a/libmamba/tests/src/specs/test_archive.cpp +++ b/libmamba/tests/src/specs/test_archive.cpp @@ -8,6 +8,7 @@ #include "mamba/specs/archive.hpp" +using namespace mamba; using namespace mamba::specs; TEST_SUITE("specs::archive") diff --git a/libmamba/tests/src/test_data.hpp b/libmamba/tests/src/test_data.hpp index 393f355138..3ed7a77881 100644 --- a/libmamba/tests/src/test_data.hpp +++ b/libmamba/tests/src/test_data.hpp @@ -8,7 +8,7 @@ #define MAMBA_CORE_URL_HPP #include "mamba/core/fsutil.hpp" -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { diff --git a/libmamba/tests/src/util/test_string.cpp b/libmamba/tests/src/util/test_string.cpp index 5b360a5e8c..7d052200fa 100644 --- a/libmamba/tests/src/util/test_string.cpp +++ b/libmamba/tests/src/util/test_string.cpp @@ -11,7 +11,7 @@ #include -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" namespace mamba::util diff --git a/libmamba/tests/src/util/test_url_manip.cpp b/libmamba/tests/src/util/test_url_manip.cpp index dff081f5d9..c0397832b9 100644 --- a/libmamba/tests/src/util/test_url_manip.cpp +++ b/libmamba/tests/src/util/test_url_manip.cpp @@ -9,12 +9,13 @@ #include -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/specs/platform.hpp" #include "mamba/util/build.hpp" #include "mamba/util/string.hpp" #include "mamba/util/url_manip.hpp" +using namespace mamba; using namespace mamba::util; TEST_SUITE("util::url_manip") @@ -180,7 +181,7 @@ TEST_SUITE("util::url_manip") TEST_CASE("path_to_url") { - std::string const win_drive = fs::absolute(fs::u8path("/")).string().substr(0, 1); + const std::string win_drive = fs::absolute(fs::u8path("/")).string().substr(0, 1); SUBCASE("/users/test/miniconda3") { @@ -219,7 +220,7 @@ TEST_SUITE("util::url_manip") TEST_CASE("path_or_url_to_url") { - std::string const win_drive = fs::absolute(fs::u8path("/")).string().substr(0, 1); + const std::string win_drive = fs::absolute(fs::u8path("/")).string().substr(0, 1); SUBCASE("/tmp/foo bar") { @@ -242,7 +243,7 @@ TEST_SUITE("util::url_manip") TEST_CASE("file_uri_unc2_to_unc4") { - for (std::string const uri : { + for (const std::string uri : { "http://example.com/test", R"(file://C:/Program\ (x74)/Users/hello\ world)", R"(file:///C:/Program\ (x74)/Users/hello\ world)", diff --git a/micromamba/src/completer.cpp b/micromamba/src/completer.cpp index 2b59eb85e9..801ef84880 100644 --- a/micromamba/src/completer.cpp +++ b/micromamba/src/completer.cpp @@ -12,6 +12,7 @@ #include "mamba/api/configuration.hpp" #include "mamba/core/output.hpp" #include "mamba/core/run.hpp" +#include "mamba/fs/filesystem.hpp" #include "mamba/util/string.hpp" @@ -35,14 +36,14 @@ complete_options( { config.load(); - auto root_prefix = config.at("root_prefix").value(); + auto root_prefix = config.at("root_prefix").value(); auto& name_start = last_args.back(); - if (fs::exists(root_prefix / "envs")) + if (mamba::fs::exists(root_prefix / "envs")) { - for (const auto& p : fs::directory_iterator(root_prefix / "envs")) + for (const auto& p : mamba::fs::directory_iterator(root_prefix / "envs")) { - if (p.is_directory() && fs::exists(p.path() / "conda-meta")) + if (p.is_directory() && mamba::fs::exists(p.path() / "conda-meta")) { auto name = p.path().filename().string(); if (mamba::util::starts_with(name, name_start)) diff --git a/micromamba/src/constructor.hpp b/micromamba/src/constructor.hpp index e1a7398abe..01fcbc0e74 100644 --- a/micromamba/src/constructor.hpp +++ b/micromamba/src/constructor.hpp @@ -7,7 +7,7 @@ #ifndef UMAMBA_CONSTRUCTOR_HPP #define UMAMBA_CONSTRUCTOR_HPP -#include "mamba/core/mamba_fs.hpp" +#include "mamba/fs/filesystem.hpp" namespace mamba { @@ -18,12 +18,12 @@ namespace mamba void construct( mamba::Configuration& config, - const fs::u8path& prefix, + const mamba::fs::u8path& prefix, bool extract_conda_pkgs, bool extract_tarball ); void -read_binary_from_stdin_and_write_to_file(fs::u8path& filename); +read_binary_from_stdin_and_write_to_file(mamba::fs::u8path& filename); #endif diff --git a/micromamba/src/env.cpp b/micromamba/src/env.cpp index 26fb65458f..b87b2b42f6 100644 --- a/micromamba/src/env.cpp +++ b/micromamba/src/env.cpp @@ -23,7 +23,7 @@ using namespace mamba; // NOLINT(build/namespaces) std::string -get_env_name(const Context& ctx, const fs::u8path& px) +get_env_name(const Context& ctx, const mamba::fs::u8path& px) { auto& ed = ctx.envs_dirs[0]; if (px == ctx.prefix_params.root_prefix) @@ -32,7 +32,7 @@ get_env_name(const Context& ctx, const fs::u8path& px) } else if (util::starts_with(px.string(), ed.string())) { - return fs::relative(px, ed).string(); + return mamba::fs::relative(px, ed).string(); } else { @@ -69,7 +69,7 @@ set_env_command(CLI::App* com, Configuration& config) pfxs.begin(), pfxs.end(), envs.begin(), - [](const fs::u8path& path) { return path.string(); } + [](const mamba::fs::u8path& path) { return path.string(); } ); res["envs"] = envs; std::cout << res.dump(4) << std::endl; diff --git a/micromamba/src/login.cpp b/micromamba/src/login.cpp index bd61bb7e31..5cefd2158a 100644 --- a/micromamba/src/login.cpp +++ b/micromamba/src/login.cpp @@ -64,13 +64,13 @@ set_logout_command(CLI::App* subcom) []() { static auto path = mamba::env::home_directory() / ".mamba" / "auth"; - fs::u8path auth_file = path / "authentication.json"; + const mamba::fs::u8path auth_file = path / "authentication.json"; if (all) { - if (fs::exists(auth_file)) + if (mamba::fs::exists(auth_file)) { - fs::remove(auth_file); + mamba::fs::remove(auth_file); } return 0; } @@ -79,7 +79,7 @@ set_logout_command(CLI::App* subcom) try { - if (fs::exists(auth_file)) + if (mamba::fs::exists(auth_file)) { auto fi = mamba::open_ifstream(auth_file); fi >> auth_info; @@ -157,16 +157,16 @@ set_login_command(CLI::App* subcom) bearer = read_stdin(); } - static auto path = mamba::env::home_directory() / ".mamba" / "auth"; - fs::create_directories(path); + static const auto path = mamba::env::home_directory() / ".mamba" / "auth"; + mamba::fs::create_directories(path); nlohmann::json auth_info; - fs::u8path auth_file = path / "authentication.json"; + const mamba::fs::u8path auth_file = path / "authentication.json"; try { - if (fs::exists(auth_file)) + if (mamba::fs::exists(auth_file)) { auto fi = mamba::open_ifstream(auth_file); fi >> auth_info;