mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 20:12:56 -04:00
refactor: add current_path() abstraction to os_access
This commit is contained in:
parent
709c6bb01d
commit
84b5b6f32a
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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<fs::path> find_binary(std::string_view name) {
|
||||
auto path_str = std::getenv("PATH");
|
||||
if (!path_str) {
|
||||
|
@ -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<std::string> splitpath(std::filesystem::path const& path);
|
||||
struct mock_dirent* find(std::filesystem::path const& path) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user