From 1ef2b61207ddec23412b05ad9b17443f29b9e9c0 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Thu, 28 Dec 2023 17:26:53 +0100 Subject: [PATCH] refactor: add canonical() to os_access --- include/dwarfs/os_access.h | 2 ++ include/dwarfs/os_access_generic.h | 2 ++ src/dwarfs/os_access_generic.cpp | 6 ++++++ src/mkdwarfs_main.cpp | 3 ++- test/test_helpers.cpp | 5 +++++ test/test_helpers.h | 3 +++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/dwarfs/os_access.h b/include/dwarfs/os_access.h index b2ef7096..adfa65bf 100644 --- a/include/dwarfs/os_access.h +++ b/include/dwarfs/os_access.h @@ -50,5 +50,7 @@ class os_access { virtual std::unique_ptr map_file(std::filesystem::path const& path, size_t size) const = 0; virtual int access(std::filesystem::path const& path, int mode) const = 0; + virtual std::filesystem::path + canonical(std::filesystem::path const& path) const = 0; }; } // namespace dwarfs diff --git a/include/dwarfs/os_access_generic.h b/include/dwarfs/os_access_generic.h index 19975d31..890cda55 100644 --- a/include/dwarfs/os_access_generic.h +++ b/include/dwarfs/os_access_generic.h @@ -42,5 +42,7 @@ class os_access_generic : public os_access { std::unique_ptr map_file(std::filesystem::path const& path, size_t size) const override; int access(std::filesystem::path const& path, int mode) const override; + std::filesystem::path + canonical(std::filesystem::path const& path) const override; }; } // namespace dwarfs diff --git a/src/dwarfs/os_access_generic.cpp b/src/dwarfs/os_access_generic.cpp index d16ece07..9162a509 100644 --- a/src/dwarfs/os_access_generic.cpp +++ b/src/dwarfs/os_access_generic.cpp @@ -23,6 +23,7 @@ #include "dwarfs/mmap.h" #include "dwarfs/os_access_generic.h" +#include "dwarfs/util.h" namespace dwarfs { @@ -77,4 +78,9 @@ int os_access_generic::access(fs::path const& path, int mode) const { #endif } +std::filesystem::path +os_access_generic::canonical(std::filesystem::path const& path) const { + return canonical_path(path); +} + } // namespace dwarfs diff --git a/src/mkdwarfs_main.cpp b/src/mkdwarfs_main.cpp index 0f551631..491d98c1 100644 --- a/src/mkdwarfs_main.cpp +++ b/src/mkdwarfs_main.cpp @@ -76,6 +76,7 @@ #include "dwarfs/mmap.h" #include "dwarfs/options.h" #include "dwarfs/options_interface.h" +#include "dwarfs/os_access.h" #include "dwarfs/overloaded.h" #include "dwarfs/program_options_helpers.h" #include "dwarfs/progress.h" @@ -768,7 +769,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) { } } - path = canonical_path(path); + path = iol.os->canonical(path); bool recompress = vm.count("recompress"); rewrite_options rw_opts; diff --git a/test/test_helpers.cpp b/test/test_helpers.cpp index 238d2957..5cd2cd2b 100644 --- a/test/test_helpers.cpp +++ b/test/test_helpers.cpp @@ -450,6 +450,11 @@ int os_access_mock::access(fs::path const& path, int) const { return access_fail_set_.count(path) ? -1 : 0; } +std::filesystem::path +os_access_mock::canonical(std::filesystem::path const& path) const { + return path; +} + std::optional find_binary(std::string_view name) { auto path_str = std::getenv("PATH"); if (!path_str) { diff --git a/test/test_helpers.h b/test/test_helpers.h index 0825ad4f..ce58b0bb 100644 --- a/test/test_helpers.h +++ b/test/test_helpers.h @@ -103,6 +103,9 @@ class os_access_mock : public os_access { int access(std::filesystem::path const&, int) const override; + std::filesystem::path + canonical(std::filesystem::path const& path) const override; + private: static std::vector splitpath(std::filesystem::path const& path); struct mock_dirent* find(std::filesystem::path const& path) const;