mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 20:41:04 -04:00
refactor(mmap): clean up and avoid boost::fs::path
if possible
This commit is contained in:
parent
917ebdf00b
commit
f1d3cf14f0
@ -32,10 +32,7 @@ namespace dwarfs {
|
|||||||
class mmap : public mmif {
|
class mmap : public mmif {
|
||||||
public:
|
public:
|
||||||
explicit mmap(std::filesystem::path const& path);
|
explicit mmap(std::filesystem::path const& path);
|
||||||
explicit mmap(std::string const& path);
|
|
||||||
explicit mmap(char const* path);
|
|
||||||
mmap(std::filesystem::path const& path, size_t size);
|
mmap(std::filesystem::path const& path, size_t size);
|
||||||
mmap(std::string const& path, size_t size);
|
|
||||||
|
|
||||||
void const* addr() const override;
|
void const* addr() const override;
|
||||||
size_t size() const override;
|
size_t size() const override;
|
||||||
|
34
src/mmap.cpp
34
src/mmap.cpp
@ -19,18 +19,16 @@
|
|||||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <folly/portability/Windows.h>
|
#include <folly/portability/Windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
|
||||||
|
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/mmap.h>
|
#include <dwarfs/mmap.h>
|
||||||
|
|
||||||
@ -63,17 +61,17 @@ int posix_advice(advice adv) {
|
|||||||
return MADV_DONTNEED;
|
return MADV_DONTNEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
DWARFS_PANIC("invalid advice");
|
||||||
|
|
||||||
return MADV_NORMAL;
|
return MADV_NORMAL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boost::filesystem::path boost_from_std_path(std::filesystem::path const& p) {
|
decltype(auto) get_file_path(std::filesystem::path const& path) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return {p.wstring()};
|
return boost::filesystem::path{path.native()};
|
||||||
#else
|
#else
|
||||||
return {p.string()};
|
return path.native();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,28 +142,18 @@ size_t mmap::size() const { return mf_.size(); }
|
|||||||
|
|
||||||
std::filesystem::path const& mmap::path() const { return path_; }
|
std::filesystem::path const& mmap::path() const { return path_; }
|
||||||
|
|
||||||
mmap::mmap(char const* path)
|
|
||||||
: mmap(std::filesystem::path(path)) {}
|
|
||||||
|
|
||||||
mmap::mmap(std::string const& path)
|
|
||||||
: mmap(std::filesystem::path(path)) {}
|
|
||||||
|
|
||||||
mmap::mmap(std::filesystem::path const& path)
|
mmap::mmap(std::filesystem::path const& path)
|
||||||
: mf_(boost_from_std_path(path), boost::iostreams::mapped_file::readonly)
|
: mf_{get_file_path(path), boost::iostreams::mapped_file::readonly}
|
||||||
, page_size_(get_page_size())
|
, page_size_{get_page_size()}
|
||||||
, path_{path} {
|
, path_{path} {
|
||||||
assert(mf_.is_open());
|
DWARFS_CHECK(mf_.is_open(), "failed to map file");
|
||||||
}
|
}
|
||||||
|
|
||||||
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::mmap(std::filesystem::path const& path, size_t size)
|
||||||
: mf_(boost_from_std_path(path), boost::iostreams::mapped_file::readonly,
|
: mf_{get_file_path(path), boost::iostreams::mapped_file::readonly, size}
|
||||||
size)
|
, page_size_{get_page_size()}
|
||||||
, page_size_(get_page_size())
|
|
||||||
, path_{path} {
|
, path_{path} {
|
||||||
assert(mf_.is_open());
|
DWARFS_CHECK(mf_.is_open(), "failed to map file");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user