MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
polyglot_file_system.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_POLYGLOT_FILE_SYSTEM_H_
27#define ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_POLYGLOT_FILE_SYSTEM_H_
28
29#include <memory>
30#include <string>
31
33
34namespace shcore {
35namespace polyglot {
36
38 public:
39 virtual ~ISeekable_channel() = default;
40 /**
41 * Tells whether or not this channel is open.
42 */
43 virtual bool is_open() = 0;
44
45 /**
46 * Closes this channel.
47 *
48 * <p> After a channel is closed, any further attempt to invoke I/O
49 * operations upon it will cause a ClosedChannelException to be thrown.
50 *
51 * <p> If this channel is already closed then invoking this method has no
52 * effect.
53 *
54 * <p> This method may be invoked at any time. If some other thread has
55 * already invoked it, however, then another invocation will block until
56 * the first invocation is complete, after which it will return without
57 * effect. </p>
58 *
59 * @throws IOException If an I/O error occurs
60 */
61 virtual void close() = 0;
62
63 /**
64 * Reads a sequence of bytes from this channel into the given buffer.
65 *
66 * <p> Bytes are read starting at this channel's current position, and
67 * then the position is updated with the number of bytes actually read.
68 * Otherwise this method behaves exactly as specified in the
69 * ReadableByteChannel interface.
70 *
71 * @throws ClosedChannelException {@inheritDoc}
72 * @throws AsynchronousCloseException {@inheritDoc}
73 * @throws ClosedByInterruptException {@inheritDoc}
74 * @throws NonReadableChannelException {@inheritDoc}
75 */
76 virtual int64_t read(void *buffer, size_t size) = 0;
77
78 /**
79 * Writes a sequence of bytes to this channel from the given buffer.
80 *
81 * <p> Bytes are written starting at this channel's current position, unless
82 * the channel is connected to an entity such as a file that is opened with
83 * the APPEND option, in which case the position is first advanced to the end.
84 * The entity to which the channel is connected is grown, if necessary, to
85 * accommodate the written bytes, and then the position is updated with the
86 * number of bytes actually written. Otherwise this method behaves exactly as
87 * specified by the WritableByteChannel interface.
88 *
89 * @throws ClosedChannelException {@inheritDoc}
90 * @throws AsynchronousCloseException {@inheritDoc}
91 * @throws ClosedByInterruptException {@inheritDoc}
92 * @throws NonWritableChannelException {@inheritDoc}
93 */
94 virtual int64_t write(const char *buffer, size_t size) = 0;
95
96 /**
97 * Returns this channel's position.
98 *
99 * @return This channel's position,
100 * a non-negative integer counting the number of bytes
101 * from the beginning of the entity to the current position
102 *
103 * @throws ClosedChannelException
104 * If this channel is closed
105 * @throws IOException
106 * If some other I/O error occurs
107 */
108 virtual int64_t position() = 0;
109
110 /**
111 * Sets this channel's position.
112 *
113 * <p> Setting the position to a value that is greater than the current size
114 * is legal but does not change the size of the entity. A later attempt to
115 * read bytes at such a position will immediately return an end-of-file
116 * indication. A later attempt to write bytes at such a position will cause
117 * the entity to grow to accommodate the new bytes; the values of any bytes
118 * between the previous end-of-file and the newly-written bytes are
119 * unspecified.
120 *
121 * <p> Setting the channel's position is not recommended when connected to
122 * an entity, typically a file, that is opened with the APPEND option.
123 * When opened for append, the position is first advanced to the end before
124 * writing.
125 *
126 * @param new_position
127 * The new position, a non-negative integer counting
128 * the number of bytes from the beginning of the entity
129 *
130 * @return This channel
131 *
132 * @throws ClosedChannelException
133 * If this channel is closed
134 * @throws IllegalArgumentException
135 * If the new position is negative
136 * @throws IOException
137 * If some other I/O error occurs
138 */
139 virtual ISeekable_channel &set_position(int64_t new_position) = 0;
140
141 /**
142 * Returns the current size of entity to which this channel is connected.
143 *
144 * @return The current size, measured in bytes
145 *
146 * @throws ClosedChannelException
147 * If this channel is closed
148 * @throws IOException
149 * If some other I/O error occurs
150 */
151 virtual int64_t size() = 0;
152
153 /**
154 * Truncates the entity, to which this channel is connected, to the given
155 * size.
156 *
157 * <p> If the given size is less than the current size then the entity is
158 * truncated, discarding any bytes beyond the new end. If the given size is
159 * greater than or equal to the current size then the entity is not modified.
160 * In either case, if the current position is greater than the given size
161 * then it is set to that size.
162 *
163 * <p> An implementation of this interface may prohibit truncation when
164 * connected to an entity, typically a file, opened with the APPEND option.
165 *
166 * @param size
167 * The new size, a non-negative byte count
168 *
169 * @return This channel
170 *
171 * @throws NonWritableChannelException
172 * If this channel was not opened for writing
173 * @throws ClosedChannelException
174 * If this channel is closed
175 * @throws IllegalArgumentException
176 * If the new size is negative
177 * @throws IOException
178 * If some other I/O error occurs
179 */
180 virtual ISeekable_channel &truncate(int64_t size) = 0;
181};
182
184
186 public:
187 virtual ~IFile_system() = default;
188
189 /**
190 * Parses a path from an URI.
191 *
192 * @param uri the URI to be converted to Path
193 * @return the Path representing given URI
194 * @throws UnsupportedOperationException when URI scheme is not
195 * supported
196 * @throws IllegalArgumentException if preconditions on the {@code uri} do not
197 * hold. The format of the URI is FileSystem specific.
198 */
199 virtual std::string parse_uri_path(const std::string &uri) = 0;
200
201 /**
202 * Parses a path from a String. This method is called only on the
203 * FileSystem with {@code file} scheme.
204 *
205 * @param path the string path to be converted to Path
206 * @return the Path
207 * @throws UnsupportedOperationException when the FileSystem supports
208 * only URI
209 * @throws IllegalArgumentException if the {@code path} string cannot be
210 * converted to a
211 * Path
212 */
213 virtual std::string parse_string_path(const std::string &path) = 0;
214
215 /**
216 * Checks existence and accessibility of a file.
217 *
218 * @param path the path to the file to check
219 * @param flags the access modes to check, as a binary mask RWX
220 * only.
221 * @throws NoSuchFileException if the file denoted by the path does not exist
222 * @throws IOException in case of IO error
223 * @throws SecurityException if this FileSystem denied the operation
224 */
225 virtual void check_access(const std::string &path, int64_t flags) = 0;
226
227 /**
228 * Creates a directory.
229 *
230 * param dir the directory to create
231 * param attrs the optional attributes to set atomically when creating the
232 * directory
233 * @throws FileAlreadyExistsException if a file on given path already exists
234 * @throws IOException in case of IO error
235 * @throws UnsupportedOperationException if the attributes contain an
236 * attribute which cannot be set atomically
237 * @throws SecurityException if this FileSystem denied the operation
238 */
239 virtual void create_directory(const std::string &path) = 0;
240
241 /**
242 * Deletes a file.
243 *
244 * @param path the path to the file to delete
245 * @throws NoSuchFileException if a file on given path does not exist
246 * @throws DirectoryNotEmptyException if the path denotes a non empty
247 * directory
248 * @throws IOException in case of IO error
249 * @throws SecurityException if this FileSystem denied the operation
250 */
251 virtual void remove(const std::string &path) = 0;
252
253 /**
254 * Opens or creates a file returning a SeekableByteChannel to access
255 * the file content.
256 *
257 * @param path the path to the file to open
258 * @return the created SeekableByteChannel
259 * @throws FileAlreadyExistsException if CREATE_NEW option is set and a file
260 * already exists on given path
261 * @throws IOException in case of IO error
262 * @throws UnsupportedOperationException if the attributes contain an
263 * attribute which cannot be set atomically
264 * @throws IllegalArgumentException in case of invalid options combination
265 * @throws SecurityException if this FileSystem denied the operation
266 */
267 virtual std::shared_ptr<ISeekable_channel> new_byte_channel(
268 const std::string &path) = 0;
269
270 /**
271 * Returns directory entries.
272 *
273 * param dir the path to the directory to iterate entries for
274 * param filter the filter
275 * @return the new DirectoryStream
276 * @throws NotDirectoryException when given path does not denote a directory
277 * @throws IOException in case of IO error
278 * @throws SecurityException if this FileSystem denied the operation
279 */
280 virtual std::shared_ptr<IDirectory_stream> new_directory_stream(
281 const std::string &path) = 0;
282
283 /**
284 * Resolves given path to an absolute path.
285 *
286 * @param path the path to resolve, may be a non normalized path
287 * @return an absolute Path
288 * @throws SecurityException if this FileSystem denied the operation
289 */
290 virtual std::string to_absolute_path(const std::string &path) = 0;
291
292 /**
293 * Returns the real (canonical) path of an existing file.
294 *
295 * @param path the path to resolve, may be a non normalized path
296 * param linkOptions options determining how the symbolic links should be
297 * handled
298 * @return an absolute canonical path
299 * @throws IOException in case of IO error
300 * @throws SecurityException if this FileSystem denied the operation
301 */
302 virtual std::string to_real_path(const std::string &path) = 0;
303};
304
305} // namespace polyglot
306} // namespace shcore
307
308#endif // ROUTER_SRC_JIT_EXECUTOR_INCLUDE_MYSQLROUTER_POLYGLOT_FILE_SYSTEM_H_
Definition: polyglot_file_system.h:183
Definition: polyglot_file_system.h:185
virtual void check_access(const std::string &path, int64_t flags)=0
Checks existence and accessibility of a file.
virtual std::shared_ptr< ISeekable_channel > new_byte_channel(const std::string &path)=0
Opens or creates a file returning a SeekableByteChannel to access the file content.
virtual std::string to_absolute_path(const std::string &path)=0
Resolves given path to an absolute path.
virtual std::string parse_uri_path(const std::string &uri)=0
Parses a path from an URI.
virtual std::string parse_string_path(const std::string &path)=0
Parses a path from a String.
virtual std::shared_ptr< IDirectory_stream > new_directory_stream(const std::string &path)=0
Returns directory entries.
virtual ~IFile_system()=default
virtual void remove(const std::string &path)=0
Deletes a file.
virtual void create_directory(const std::string &path)=0
Creates a directory.
virtual std::string to_real_path(const std::string &path)=0
Returns the real (canonical) path of an existing file.
Definition: polyglot_file_system.h:37
virtual ISeekable_channel & set_position(int64_t new_position)=0
Sets this channel's position.
virtual int64_t position()=0
Returns this channel's position.
virtual int64_t read(void *buffer, size_t size)=0
Reads a sequence of bytes from this channel into the given buffer.
virtual int64_t size()=0
Returns the current size of entity to which this channel is connected.
virtual void close()=0
Closes this channel.
virtual bool is_open()=0
Tells whether or not this channel is open.
virtual int64_t write(const char *buffer, size_t size)=0
Writes a sequence of bytes to this channel from the given buffer.
virtual ISeekable_channel & truncate(int64_t size)=0
Truncates the entity, to which this channel is connected, to the given size.
static int flags[50]
Definition: hp_test1.cc:40
static char * path
Definition: mysqldump.cc:150
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Definition: file_system_exceptions.h:34