|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <iosfwd> |
|
#include <memory> |
|
#include <string> |
|
#include <string_view> |
|
#include <vector> |
|
|
|
#include "arrow/filesystem/filesystem.h" |
|
#include "arrow/util/windows_fixup.h" |
|
|
|
namespace arrow::fs::internal { |
|
|
|
struct MockDirInfo { |
|
std::string full_path; |
|
TimePoint mtime; |
|
|
|
bool operator==(const MockDirInfo& other) const { |
|
return mtime == other.mtime && full_path == other.full_path; |
|
} |
|
|
|
ARROW_FRIEND_EXPORT friend std::ostream& operator<<(std::ostream&, const MockDirInfo&); |
|
}; |
|
|
|
struct MockFileInfo { |
|
std::string full_path; |
|
TimePoint mtime; |
|
std::string_view data; |
|
|
|
bool operator==(const MockFileInfo& other) const { |
|
return mtime == other.mtime && full_path == other.full_path && data == other.data; |
|
} |
|
|
|
ARROW_FRIEND_EXPORT friend std::ostream& operator<<(std::ostream&, const MockFileInfo&); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class ARROW_EXPORT MockFileSystem : public FileSystem { |
|
public: |
|
explicit MockFileSystem(TimePoint current_time, |
|
const io::IOContext& = io::default_io_context()); |
|
~MockFileSystem() override; |
|
|
|
std::string type_name() const override { return "mock"; } |
|
|
|
bool Equals(const FileSystem& other) const override; |
|
Result<std::string> PathFromUri(const std::string& uri_string) const override; |
|
|
|
|
|
using FileSystem::CreateDir; |
|
using FileSystem::DeleteDirContents; |
|
using FileSystem::GetFileInfo; |
|
using FileSystem::OpenAppendStream; |
|
using FileSystem::OpenOutputStream; |
|
|
|
|
|
Result<FileInfo> GetFileInfo(const std::string& path) override; |
|
Result<std::vector<FileInfo>> GetFileInfo(const FileSelector& select) override; |
|
|
|
Status CreateDir(const std::string& path, bool recursive) override; |
|
|
|
Status DeleteDir(const std::string& path) override; |
|
Status DeleteDirContents(const std::string& path, bool missing_dir_ok) override; |
|
Status DeleteRootDirContents() override; |
|
|
|
Status DeleteFile(const std::string& path) override; |
|
|
|
Status Move(const std::string& src, const std::string& dest) override; |
|
|
|
Status CopyFile(const std::string& src, const std::string& dest) override; |
|
|
|
Result<std::shared_ptr<io::InputStream>> OpenInputStream( |
|
const std::string& path) override; |
|
Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile( |
|
const std::string& path) override; |
|
Result<std::shared_ptr<io::OutputStream>> OpenOutputStream( |
|
const std::string& path, |
|
const std::shared_ptr<const KeyValueMetadata>& metadata) override; |
|
Result<std::shared_ptr<io::OutputStream>> OpenAppendStream( |
|
const std::string& path, |
|
const std::shared_ptr<const KeyValueMetadata>& metadata) override; |
|
|
|
|
|
|
|
std::vector<MockDirInfo> AllDirs(); |
|
std::vector<MockFileInfo> AllFiles(); |
|
|
|
|
|
Status CreateFile(const std::string& path, std::string_view content, |
|
bool recursive = true); |
|
|
|
|
|
|
|
static Result<std::shared_ptr<FileSystem>> Make(TimePoint current_time, |
|
const std::vector<FileInfo>& infos); |
|
|
|
class Impl; |
|
|
|
protected: |
|
std::unique_ptr<Impl> impl_; |
|
}; |
|
|
|
class ARROW_EXPORT MockAsyncFileSystem : public MockFileSystem { |
|
public: |
|
explicit MockAsyncFileSystem(TimePoint current_time, |
|
const io::IOContext& io_context = io::default_io_context()) |
|
: MockFileSystem(current_time, io_context) { |
|
default_async_is_sync_ = false; |
|
} |
|
|
|
FileInfoGenerator GetFileInfoGenerator(const FileSelector& select) override; |
|
}; |
|
|
|
} |
|
|