mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 04:19:10 -04:00
Add path() to mmif/mmap
This commit is contained in:
parent
aca1417be2
commit
bacdef0ac3
@ -22,8 +22,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include <boost/iostreams/device/mapped_file.hpp>
|
||||
|
||||
@ -45,8 +43,11 @@ class mmap : public mmif {
|
||||
std::error_code release(file_off_t offset, size_t size) override;
|
||||
std::error_code release_until(file_off_t offset) override;
|
||||
|
||||
std::filesystem::path const& path() const override;
|
||||
|
||||
private:
|
||||
boost::iostreams::mapped_file mutable mf_;
|
||||
uint64_t const page_size_;
|
||||
std::filesystem::path const path_;
|
||||
};
|
||||
} // namespace dwarfs
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
@ -57,5 +58,7 @@ class mmif : public boost::noncopyable {
|
||||
virtual std::error_code lock(file_off_t offset, size_t size) = 0;
|
||||
virtual std::error_code release(file_off_t offset, size_t size) = 0;
|
||||
virtual std::error_code release_until(file_off_t offset) = 0;
|
||||
|
||||
virtual std::filesystem::path const& path() const = 0;
|
||||
};
|
||||
} // namespace dwarfs
|
||||
|
@ -132,12 +132,15 @@ void const* mmap::addr() const { return mf_.const_data(); }
|
||||
|
||||
size_t mmap::size() const { return mf_.size(); }
|
||||
|
||||
std::filesystem::path const& mmap::path() const { return path_; }
|
||||
|
||||
mmap::mmap(std::string const& path)
|
||||
: mmap(std::filesystem::path(path)) {}
|
||||
|
||||
mmap::mmap(std::filesystem::path const& path)
|
||||
: mf_(boost_from_std_path(path), boost::iostreams::mapped_file::readonly)
|
||||
, page_size_(get_page_size()) {
|
||||
, page_size_(get_page_size())
|
||||
, path_{path} {
|
||||
assert(mf_.is_open());
|
||||
}
|
||||
|
||||
@ -147,7 +150,8 @@ mmap::mmap(std::string 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,
|
||||
size)
|
||||
, page_size_(get_page_size()) {
|
||||
, page_size_(get_page_size())
|
||||
, path_{path} {
|
||||
assert(mf_.is_open());
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,18 @@ namespace test {
|
||||
class mmap_mock : public mmif {
|
||||
public:
|
||||
mmap_mock(const std::string& data)
|
||||
: m_data(data) {}
|
||||
: data_(data)
|
||||
, path_{"<mock-file>"} {}
|
||||
|
||||
void const* addr() const override { return m_data.data(); }
|
||||
mmap_mock(const std::string& data, std::filesystem::path const& path)
|
||||
: data_{data}
|
||||
, path_{path} {}
|
||||
|
||||
size_t size() const override { return m_data.size(); }
|
||||
void const* addr() const override { return data_.data(); }
|
||||
|
||||
size_t size() const override { return data_.size(); }
|
||||
|
||||
std::filesystem::path const& path() const override { return path_; }
|
||||
|
||||
std::error_code lock(file_off_t, size_t) override {
|
||||
return std::error_code();
|
||||
@ -44,7 +51,8 @@ class mmap_mock : public mmif {
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string m_data;
|
||||
std::string const data_;
|
||||
std::filesystem::path const path_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
Loading…
x
Reference in New Issue
Block a user