diff --git a/include/dwarfs/os_access.h b/include/dwarfs/os_access.h index adfa65bf..d33fffef 100644 --- a/include/dwarfs/os_access.h +++ b/include/dwarfs/os_access.h @@ -52,5 +52,6 @@ class os_access { virtual int access(std::filesystem::path const& path, int mode) const = 0; virtual std::filesystem::path canonical(std::filesystem::path const& path) const = 0; + virtual std::filesystem::path current_path() const = 0; }; } // namespace dwarfs diff --git a/include/dwarfs/os_access_generic.h b/include/dwarfs/os_access_generic.h index 890cda55..01998aa4 100644 --- a/include/dwarfs/os_access_generic.h +++ b/include/dwarfs/os_access_generic.h @@ -44,5 +44,6 @@ class os_access_generic : public os_access { int access(std::filesystem::path const& path, int mode) const override; std::filesystem::path canonical(std::filesystem::path const& path) const override; + std::filesystem::path current_path() const override; }; } // namespace dwarfs diff --git a/src/dwarfs/os_access_generic.cpp b/src/dwarfs/os_access_generic.cpp index 9162a509..371de4b2 100644 --- a/src/dwarfs/os_access_generic.cpp +++ b/src/dwarfs/os_access_generic.cpp @@ -78,9 +78,10 @@ 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 { +fs::path os_access_generic::canonical(fs::path const& path) const { return canonical_path(path); } +fs::path os_access_generic::current_path() const { return fs::current_path(); } + } // namespace dwarfs diff --git a/src/mkdwarfs_main.cpp b/src/mkdwarfs_main.cpp index 0f4bc259..875bb2bc 100644 --- a/src/mkdwarfs_main.cpp +++ b/src/mkdwarfs_main.cpp @@ -753,7 +753,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) { options.with_specials = true; if (!vm.count("input")) { - path = std::filesystem::current_path(); + path = iol.os->current_path(); } std::filesystem::path input_list_path(input_list_str); diff --git a/test/test_helpers.cpp b/test/test_helpers.cpp index 5cd2cd2b..a4e669e3 100644 --- a/test/test_helpers.cpp +++ b/test/test_helpers.cpp @@ -455,6 +455,10 @@ os_access_mock::canonical(std::filesystem::path const& path) const { return path; } +std::filesystem::path os_access_mock::current_path() const { + return root_->name; +} + 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 a5093ac4..a205f784 100644 --- a/test/test_helpers.h +++ b/test/test_helpers.h @@ -106,6 +106,8 @@ class os_access_mock : public os_access { std::filesystem::path canonical(std::filesystem::path const& path) const override; + std::filesystem::path current_path() const override; + private: static std::vector splitpath(std::filesystem::path const& path); struct mock_dirent* find(std::filesystem::path const& path) const;