|
| 1 | +/** |
| 2 | + * @file failing_fs.h |
| 3 | + * |
| 4 | + * @section LICENSE |
| 5 | + * |
| 6 | + * The MIT License |
| 7 | + * |
| 8 | + * @copyright Copyright (c) 2025 TileDB, Inc. |
| 9 | + * |
| 10 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | + * of this software and associated documentation files (the "Software"), to deal |
| 12 | + * in the Software without restriction, including without limitation the rights |
| 13 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | + * copies of the Software, and to permit persons to whom the Software is |
| 15 | + * furnished to do so, subject to the following conditions: |
| 16 | + * |
| 17 | + * The above copyright notice and this permission notice shall be included in |
| 18 | + * all copies or substantial portions of the Software. |
| 19 | + * |
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 26 | + * THE SOFTWARE. |
| 27 | + * |
| 28 | + * @section DESCRIPTION |
| 29 | + * |
| 30 | + * This file defines the FailingFS class. |
| 31 | + */ |
| 32 | + |
| 33 | +#ifndef TILEDB_FAILINGFS_H |
| 34 | +#define TILEDB_FAILINGFS_h |
| 35 | + |
| 36 | +#include "tiledb/common/assert.h" |
| 37 | +#include "tiledb/sm/filesystem/filesystem_base.h" |
| 38 | + |
| 39 | +namespace tiledb::sm { |
| 40 | +/** |
| 41 | + * Implements FilesystemBase by always throwing FilesystemException. |
| 42 | + */ |
| 43 | +class FailingFS : public FilesystemBase { |
| 44 | + public: |
| 45 | + /** |
| 46 | + * Constructor. |
| 47 | + * |
| 48 | + * @param uri_scheme The URI scheme this object will claim to support. |
| 49 | + * @param message The message of the exceptions this object's operations will throw. |
| 50 | + */ |
| 51 | + FailingFS(const std::string& uri_scheme, const std::string& message = "") |
| 52 | + : uri_scheme_(uri_scheme) |
| 53 | + , message_(message) { |
| 54 | + iassert(!uri_scheme.empty()); |
| 55 | + } |
| 56 | + |
| 57 | + bool supports_uri(const URI& uri) const override { |
| 58 | + return uri.backend_name() == uri_scheme_; |
| 59 | + } |
| 60 | + |
| 61 | + virtual void create_dir(const URI&) const override { |
| 62 | + throw get_exception(); |
| 63 | + } |
| 64 | + |
| 65 | + virtual void touch(const URI&) const override { |
| 66 | + throw get_exception(); |
| 67 | + } |
| 68 | + |
| 69 | + virtual bool is_dir(const URI&) const override { |
| 70 | + throw get_exception(); |
| 71 | + } |
| 72 | + |
| 73 | + virtual bool is_file(const URI&) const override { |
| 74 | + throw get_exception(); |
| 75 | + } |
| 76 | + |
| 77 | + virtual void remove_dir(const URI&) const override { |
| 78 | + throw get_exception(); |
| 79 | + } |
| 80 | + |
| 81 | + virtual void remove_file(const URI&) const override { |
| 82 | + throw get_exception(); |
| 83 | + } |
| 84 | + |
| 85 | + virtual uint64_t file_size(const URI&) const override { |
| 86 | + throw get_exception(); |
| 87 | + } |
| 88 | + |
| 89 | + virtual std::vector<tiledb::common::filesystem::directory_entry> |
| 90 | + ls_with_sizes(const URI&) const override { |
| 91 | + throw get_exception(); |
| 92 | + } |
| 93 | + |
| 94 | + virtual LsObjects ls_filtered(const URI&, ResultFilter, bool) const override { |
| 95 | + throw get_exception(); |
| 96 | + } |
| 97 | + |
| 98 | + virtual LsObjects ls_filtered_v2( |
| 99 | + const URI&, ResultFilterV2, bool) const override { |
| 100 | + throw get_exception(); |
| 101 | + } |
| 102 | + |
| 103 | + virtual void move_file(const URI&, const URI&) const override { |
| 104 | + throw get_exception(); |
| 105 | + } |
| 106 | + |
| 107 | + virtual void move_dir(const URI&, const URI&) const override { |
| 108 | + throw get_exception(); |
| 109 | + } |
| 110 | + |
| 111 | + virtual void copy_file(const URI&, const URI&) const override { |
| 112 | + throw get_exception(); |
| 113 | + } |
| 114 | + |
| 115 | + virtual void copy_dir(const URI&, const URI&) const override { |
| 116 | + throw get_exception(); |
| 117 | + } |
| 118 | + |
| 119 | + virtual uint64_t read(const URI&, uint64_t, void*, uint64_t) override { |
| 120 | + throw get_exception(); |
| 121 | + } |
| 122 | + |
| 123 | + virtual void flush(const URI&, bool) override { |
| 124 | + throw get_exception(); |
| 125 | + } |
| 126 | + |
| 127 | + void sync(const URI&) const override { |
| 128 | + throw get_exception(); |
| 129 | + } |
| 130 | + |
| 131 | + virtual void write(const URI&, const void*, uint64_t, bool) override { |
| 132 | + throw get_exception(); |
| 133 | + } |
| 134 | + |
| 135 | + virtual bool is_bucket(const URI&) const override { |
| 136 | + throw get_exception(); |
| 137 | + } |
| 138 | + |
| 139 | + virtual bool is_empty_bucket(const URI&) const override { |
| 140 | + throw get_exception(); |
| 141 | + } |
| 142 | + |
| 143 | + virtual void create_bucket(const URI&) const override { |
| 144 | + throw get_exception(); |
| 145 | + } |
| 146 | + |
| 147 | + virtual void remove_bucket(const URI&) const override { |
| 148 | + throw get_exception(); |
| 149 | + } |
| 150 | + |
| 151 | + virtual void empty_bucket(const URI&) const override { |
| 152 | + throw get_exception(); |
| 153 | + } |
| 154 | + |
| 155 | + private: |
| 156 | + const std::string uri_scheme_, message_; |
| 157 | + |
| 158 | + FilesystemException get_exception() const { |
| 159 | + return FilesystemException(message_); |
| 160 | + } |
| 161 | +}; |
| 162 | +} // namespace tiledb::sm |
| 163 | +#endif // TILEDB_FAILINGFS_H |
0 commit comments