mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-16 15:58:06 -04:00
More moving from std::string to fs::path
This commit is contained in:
parent
2836a488ea
commit
5a17c877a3
@ -459,7 +459,7 @@ void block_manager_<LoggerPolicy>::add_inode(std::shared_ptr<inode> ino) {
|
||||
auto e = ino->any();
|
||||
|
||||
if (size_t size = e->size(); size > 0) {
|
||||
auto mm = os_->map_file(e->path(), size);
|
||||
auto mm = os_->map_file(e->fs_path(), size);
|
||||
|
||||
LOG_TRACE << "adding inode " << ino->num() << " [" << ino->any()->name()
|
||||
<< "] - size: " << size;
|
||||
|
@ -384,7 +384,7 @@ const std::string& link::linkname() const { return link_; }
|
||||
void link::accept(entry_visitor& v, bool) { v.visit(this); }
|
||||
|
||||
void link::scan(os_access& os, progress& prog) {
|
||||
link_ = os.read_symlink(path());
|
||||
link_ = u8string_to_string(os.read_symlink(path()).u8string());
|
||||
prog.original_size += size();
|
||||
prog.symlink_size += size();
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ void file_scanner_::hash_file(file* p) {
|
||||
std::shared_ptr<mmif> mm;
|
||||
|
||||
if (size > 0) {
|
||||
mm = os_.map_file(p->path(), size);
|
||||
mm = os_.map_file(p->fs_path(), size);
|
||||
}
|
||||
|
||||
prog_.current.store(p);
|
||||
@ -313,7 +313,7 @@ void file_scanner_::add_inode(file* p) {
|
||||
std::shared_ptr<mmif> mm;
|
||||
auto const size = p->size();
|
||||
if (size > 0) {
|
||||
mm = os_.map_file(p->path(), size);
|
||||
mm = os_.map_file(p->fs_path(), size);
|
||||
}
|
||||
inode->scan(mm, ino_opts_);
|
||||
++prog_.similarity_scans;
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "dwarfs/error.h"
|
||||
#include "dwarfs/mmap.h"
|
||||
|
||||
@ -111,21 +113,23 @@ void const* mmap::addr() const { return mf_.const_data(); }
|
||||
size_t mmap::size() const { return mf_.size(); }
|
||||
|
||||
mmap::mmap(std::string const& path)
|
||||
: mf_(path, boost::iostreams::mapped_file::readonly)
|
||||
, page_size_(get_page_size()) {
|
||||
assert(mf_.is_open());
|
||||
}
|
||||
: mmap(std::filesystem::path(path)) {}
|
||||
|
||||
mmap::mmap(std::filesystem::path const& path)
|
||||
: mmap(path.string()) {}
|
||||
|
||||
mmap::mmap(std::string const& path, size_t size)
|
||||
: mf_(path, boost::iostreams::mapped_file::readonly, size)
|
||||
: mf_(boost::filesystem::path(path.wstring()),
|
||||
boost::iostreams::mapped_file::readonly)
|
||||
, page_size_(get_page_size()) {
|
||||
assert(mf_.is_open());
|
||||
}
|
||||
|
||||
mmap::mmap(std::string const& path, size_t size)
|
||||
: mmap(std::filesystem::path(path), size) {}
|
||||
|
||||
mmap::mmap(std::filesystem::path const& path, size_t size)
|
||||
: mmap(path.string(), size) {}
|
||||
: mf_(boost::filesystem::path(path.wstring()),
|
||||
boost::iostreams::mapped_file::readonly, size)
|
||||
, page_size_(get_page_size()) {
|
||||
assert(mf_.is_open());
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -66,12 +66,14 @@ file_stat make_file_stat(fs::path const& path) {
|
||||
rv.blksize = 0;
|
||||
rv.blocks = 0;
|
||||
|
||||
auto wps = path.wstring();
|
||||
|
||||
if (status.type() == fs::file_type::symlink) {
|
||||
::WIN32_FILE_ATTRIBUTE_DATA info;
|
||||
if (::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &info) ==
|
||||
if (::GetFileAttributesExW(wps.c_str(), GetFileExInfoStandard, &info) ==
|
||||
0) {
|
||||
throw std::system_error(::GetLastError(), std::system_category(),
|
||||
"GetFileAttributesExA");
|
||||
"GetFileAttributesExW");
|
||||
}
|
||||
rv.dev = 0;
|
||||
rv.ino = 0;
|
||||
@ -86,7 +88,7 @@ file_stat make_file_stat(fs::path const& path) {
|
||||
rv.ctime = time_from_filetime(info.ftCreationTime);
|
||||
} else {
|
||||
struct ::__stat64 st;
|
||||
if (::_stat64(path.c_str(), &st) != 0) {
|
||||
if (::_wstat64(wps.c_str(), &st) != 0) {
|
||||
throw std::system_error(errno, std::generic_category(), "_stat64");
|
||||
}
|
||||
rv.dev = st.st_dev;
|
||||
@ -109,7 +111,7 @@ file_stat make_file_stat(fs::path const& path) {
|
||||
file_stat make_file_stat(fs::path const& path) {
|
||||
struct ::stat st;
|
||||
|
||||
if (::lstat(path.c_str(), &st) != 0) {
|
||||
if (::lstat(path.string().c_str(), &st) != 0) {
|
||||
throw std::system_error(errno, std::generic_category(), "lstat");
|
||||
}
|
||||
|
||||
@ -173,7 +175,11 @@ os_access_generic::map_file(fs::path const& path, size_t size) const {
|
||||
}
|
||||
|
||||
int os_access_generic::access(fs::path const& path, int mode) const {
|
||||
return ::access(path.c_str(), mode);
|
||||
#ifdef _WIN32
|
||||
return ::_waccess(path.wstring().c_str(), mode);
|
||||
#else
|
||||
return ::access(path.string().c_str(), mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -457,7 +457,7 @@ scanner_<LoggerPolicy>::scan_tree(std::filesystem::path const& path,
|
||||
DWARFS_CHECK(parent, "expected directory");
|
||||
|
||||
queue.pop_front();
|
||||
const std::string& path = parent->path();
|
||||
auto path = parent->fs_path();
|
||||
|
||||
try {
|
||||
auto d = os_->opendir(path);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <folly/portability/Unistd.h>
|
||||
|
||||
#include "dwarfs/overloaded.h"
|
||||
#include "dwarfs/util.h"
|
||||
#include "loremipsum.h"
|
||||
#include "mmap_mock.h"
|
||||
#include "test_helpers.h"
|
||||
@ -287,8 +288,10 @@ size_t os_access_mock::size() const { return root_ ? root_->size() : 0; }
|
||||
|
||||
std::vector<std::string> os_access_mock::splitpath(fs::path const& path) {
|
||||
std::vector<std::string> parts;
|
||||
folly::split('/', path.string(), parts);
|
||||
while (!parts.empty() && parts.front().empty()) {
|
||||
for (auto const& p : path) {
|
||||
parts.emplace_back(u8string_to_string(p.u8string()));
|
||||
}
|
||||
while (!parts.empty() && (parts.front().empty() || parts.front() == "/")) {
|
||||
parts.erase(parts.begin());
|
||||
}
|
||||
return parts;
|
||||
|
Loading…
x
Reference in New Issue
Block a user