File indexing completed on 2025-08-28 08:26:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <iosfwd>
0021 #include <memory>
0022 #include <string>
0023 #include <string_view>
0024 #include <vector>
0025
0026 #include "arrow/filesystem/filesystem.h"
0027 #include "arrow/util/windows_fixup.h"
0028
0029 namespace arrow::fs::internal {
0030
0031 struct MockDirInfo {
0032 std::string full_path;
0033 TimePoint mtime;
0034
0035 bool operator==(const MockDirInfo& other) const {
0036 return mtime == other.mtime && full_path == other.full_path;
0037 }
0038
0039 ARROW_FRIEND_EXPORT friend std::ostream& operator<<(std::ostream&, const MockDirInfo&);
0040 };
0041
0042 struct MockFileInfo {
0043 std::string full_path;
0044 TimePoint mtime;
0045 std::string_view data;
0046
0047 bool operator==(const MockFileInfo& other) const {
0048 return mtime == other.mtime && full_path == other.full_path && data == other.data;
0049 }
0050
0051 ARROW_FRIEND_EXPORT friend std::ostream& operator<<(std::ostream&, const MockFileInfo&);
0052 };
0053
0054
0055
0056
0057
0058 class ARROW_EXPORT MockFileSystem : public FileSystem {
0059 public:
0060 explicit MockFileSystem(TimePoint current_time,
0061 const io::IOContext& = io::default_io_context());
0062 ~MockFileSystem() override;
0063
0064 std::string type_name() const override { return "mock"; }
0065
0066 bool Equals(const FileSystem& other) const override;
0067 Result<std::string> PathFromUri(const std::string& uri_string) const override;
0068
0069
0070 using FileSystem::CreateDir;
0071 using FileSystem::DeleteDirContents;
0072 using FileSystem::GetFileInfo;
0073 using FileSystem::OpenAppendStream;
0074 using FileSystem::OpenOutputStream;
0075
0076
0077 Result<FileInfo> GetFileInfo(const std::string& path) override;
0078 Result<std::vector<FileInfo>> GetFileInfo(const FileSelector& select) override;
0079
0080 Status CreateDir(const std::string& path, bool recursive) override;
0081
0082 Status DeleteDir(const std::string& path) override;
0083 Status DeleteDirContents(const std::string& path, bool missing_dir_ok) override;
0084 Status DeleteRootDirContents() override;
0085
0086 Status DeleteFile(const std::string& path) override;
0087
0088 Status Move(const std::string& src, const std::string& dest) override;
0089
0090 Status CopyFile(const std::string& src, const std::string& dest) override;
0091
0092 Result<std::shared_ptr<io::InputStream>> OpenInputStream(
0093 const std::string& path) override;
0094 Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile(
0095 const std::string& path) override;
0096 Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
0097 const std::string& path,
0098 const std::shared_ptr<const KeyValueMetadata>& metadata) override;
0099 Result<std::shared_ptr<io::OutputStream>> OpenAppendStream(
0100 const std::string& path,
0101 const std::shared_ptr<const KeyValueMetadata>& metadata) override;
0102
0103
0104
0105 std::vector<MockDirInfo> AllDirs();
0106 std::vector<MockFileInfo> AllFiles();
0107
0108
0109 Status CreateFile(const std::string& path, std::string_view content,
0110 bool recursive = true);
0111
0112
0113
0114 static Result<std::shared_ptr<FileSystem>> Make(TimePoint current_time,
0115 const std::vector<FileInfo>& infos);
0116
0117 class Impl;
0118
0119 protected:
0120 std::unique_ptr<Impl> impl_;
0121 };
0122
0123 class ARROW_EXPORT MockAsyncFileSystem : public MockFileSystem {
0124 public:
0125 explicit MockAsyncFileSystem(TimePoint current_time,
0126 const io::IOContext& io_context = io::default_io_context())
0127 : MockFileSystem(current_time, io_context) {
0128 default_async_is_sync_ = false;
0129 }
0130
0131 FileInfoGenerator GetFileInfoGenerator(const FileSelector& select) override;
0132 };
0133
0134 }