mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 12:28:13 -04:00
refactor: add canonical() to os_access
This commit is contained in:
parent
1f8ad8fbc7
commit
1ef2b61207
@ -50,5 +50,7 @@ class os_access {
|
||||
virtual std::unique_ptr<mmif>
|
||||
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
|
||||
|
@ -42,5 +42,7 @@ class os_access_generic : public os_access {
|
||||
std::unique_ptr<mmif>
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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<fs::path> find_binary(std::string_view name) {
|
||||
auto path_str = std::getenv("PATH");
|
||||
if (!path_str) {
|
||||
|
@ -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<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