mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 13:04:15 -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 int access(std::filesystem::path const& path, int mode) const = 0;
|
||||||
virtual std::filesystem::path
|
virtual std::filesystem::path
|
||||||
canonical(std::filesystem::path const& path) const = 0;
|
canonical(std::filesystem::path const& path) const = 0;
|
||||||
|
virtual std::filesystem::path current_path() const = 0;
|
||||||
};
|
};
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
@ -44,5 +44,6 @@ class os_access_generic : public os_access {
|
|||||||
int access(std::filesystem::path const& path, int mode) const override;
|
int access(std::filesystem::path const& path, int mode) const override;
|
||||||
std::filesystem::path
|
std::filesystem::path
|
||||||
canonical(std::filesystem::path const& path) const override;
|
canonical(std::filesystem::path const& path) const override;
|
||||||
|
std::filesystem::path current_path() const override;
|
||||||
};
|
};
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
@ -78,9 +78,10 @@ int os_access_generic::access(fs::path const& path, int mode) const {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path
|
fs::path os_access_generic::canonical(fs::path const& path) const {
|
||||||
os_access_generic::canonical(std::filesystem::path const& path) const {
|
|
||||||
return canonical_path(path);
|
return canonical_path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs::path os_access_generic::current_path() const { return fs::current_path(); }
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
@ -753,7 +753,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
|||||||
options.with_specials = true;
|
options.with_specials = true;
|
||||||
|
|
||||||
if (!vm.count("input")) {
|
if (!vm.count("input")) {
|
||||||
path = std::filesystem::current_path();
|
path = iol.os->current_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path input_list_path(input_list_str);
|
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;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::filesystem::path os_access_mock::current_path() const {
|
||||||
|
return root_->name;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<fs::path> find_binary(std::string_view name) {
|
std::optional<fs::path> find_binary(std::string_view name) {
|
||||||
auto path_str = std::getenv("PATH");
|
auto path_str = std::getenv("PATH");
|
||||||
if (!path_str) {
|
if (!path_str) {
|
||||||
|
@ -106,6 +106,8 @@ class os_access_mock : public os_access {
|
|||||||
std::filesystem::path
|
std::filesystem::path
|
||||||
canonical(std::filesystem::path const& path) const override;
|
canonical(std::filesystem::path const& path) const override;
|
||||||
|
|
||||||
|
std::filesystem::path current_path() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::vector<std::string> splitpath(std::filesystem::path const& path);
|
static std::vector<std::string> splitpath(std::filesystem::path const& path);
|
||||||
struct mock_dirent* find(std::filesystem::path const& path) const;
|
struct mock_dirent* find(std::filesystem::path const& path) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user