Coverage Report

Created: 2026-05-21 20:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/fs/local_file_system.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "io/fs/local_file_system.h"
19
20
#include <fcntl.h>
21
#include <fmt/format.h>
22
#include <glob.h>
23
#include <glog/logging.h>
24
#include <openssl/md5.h>
25
#include <sys/mman.h>
26
#include <sys/stat.h>
27
#include <unistd.h>
28
29
#include <filesystem>
30
#include <iomanip>
31
#include <istream>
32
#include <system_error>
33
#include <utility>
34
35
#include "common/exception.h"
36
#include "cpp/sync_point.h"
37
#include "io/fs/err_utils.h"
38
#include "io/fs/file_system.h"
39
#include "io/fs/file_writer.h"
40
#include "io/fs/local_file_reader.h"
41
#include "io/fs/local_file_writer.h"
42
#include "runtime/thread_context.h"
43
#include "storage/data_dir.h"
44
#include "util/async_io.h" // IWYU pragma: keep
45
#include "util/debug_points.h"
46
#include "util/defer_op.h"
47
48
namespace doris::io {
49
50
std::filesystem::perms LocalFileSystem::PERMS_OWNER_RW =
51
        std::filesystem::perms::owner_read | std::filesystem::perms::owner_write;
52
53
8
LocalFileSystem::LocalFileSystem() : FileSystem(FileSystem::TMP_FS_ID, FileSystemType::LOCAL) {}
54
55
3
LocalFileSystem::~LocalFileSystem() = default;
56
57
Status LocalFileSystem::create_file_impl(const Path& file, FileWriterPtr* writer,
58
145k
                                         const FileWriterOptions* opts) {
59
18.4E
    VLOG_DEBUG << "create file: " << file.native()
60
18.4E
               << ", sync_data: " << (opts ? opts->sync_file_data : true);
61
145k
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileSystem::create_file_impl",
62
145k
                                      Status::IOError("inject io error"));
63
    // O_TRUNC: if file already exists (last tmp), clear the content
64
145k
    int fd = ::open(file.c_str(), O_TRUNC | O_WRONLY | O_CREAT | O_CLOEXEC, 0666);
65
145k
    DBUG_EXECUTE_IF("LocalFileSystem.create_file_impl.open_file_failed", {
66
        // spare '.testfile' to make bad disk checker happy
67
145k
        auto sub_path = dp->param<std::string>("sub_path", "");
68
145k
        if ((sub_path.empty() && file.filename().compare(kTestFilePath)) ||
69
145k
            (!sub_path.empty() && file.native().find(sub_path) != std::string::npos)) {
70
145k
            ::close(fd);
71
145k
            fd = -1;
72
145k
            errno = EIO;
73
145k
            LOG(WARNING) << Status::IOError("debug open io error: {}", file.native());
74
145k
        }
75
145k
    });
76
145k
    if (-1 == fd) {
77
3
        return localfs_error(errno, fmt::format("failed to create file {}", file.native()));
78
3
    }
79
145k
    bool sync_data = opts != nullptr ? opts->sync_file_data : true;
80
145k
    *writer = std::make_unique<LocalFileWriter>(file, fd, sync_data);
81
145k
    return Status::OK();
82
145k
}
83
84
Status LocalFileSystem::open_file_impl(const Path& file, FileReaderSPtr* reader,
85
722k
                                       const FileReaderOptions* opts) {
86
722k
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileSystem::open_file_impl",
87
722k
                                      Status::IOError("inject io error"));
88
722k
    int64_t fsize = opts ? opts->file_size : -1;
89
722k
    if (fsize < 0) {
90
720k
        RETURN_IF_ERROR(file_size_impl(file, &fsize));
91
720k
    }
92
717k
    int fd = -1;
93
717k
    RETRY_ON_EINTR(fd, open(file.c_str(), O_RDONLY));
94
717k
    DBUG_EXECUTE_IF("LocalFileSystem.create_file_impl.open_file_failed", {
95
        // spare '.testfile' to make bad disk checker happy
96
717k
        auto sub_path = dp->param<std::string>("sub_path", "");
97
717k
        if ((sub_path.empty() && file.filename().compare(kTestFilePath)) ||
98
717k
            (!sub_path.empty() && file.native().find(sub_path) != std::string::npos)) {
99
717k
            ::close(fd);
100
717k
            fd = -1;
101
717k
            errno = EIO;
102
717k
            LOG(WARNING) << Status::IOError("debug open io error: {}", file.native());
103
717k
        }
104
717k
    });
105
717k
    if (fd < 0) {
106
0
        return localfs_error(errno, fmt::format("failed to open {}", file.native()));
107
0
    }
108
717k
    *reader = std::make_shared<LocalFileReader>(file, fsize, fd);
109
717k
    return Status::OK();
110
717k
}
111
112
248k
Status LocalFileSystem::create_directory_impl(const Path& dir, bool failed_if_exists) {
113
18.4E
    VLOG_DEBUG << "create directory: " << dir.native()
114
18.4E
               << ", failed_if_exists: " << failed_if_exists;
115
248k
    bool exists = true;
116
248k
    RETURN_IF_ERROR(exists_impl(dir, &exists));
117
248k
    if (exists && failed_if_exists) {
118
0
        return Status::AlreadyExist("failed to create {}, already exists", dir.native());
119
0
    }
120
248k
    if (!exists) {
121
234k
        std::error_code ec;
122
234k
        std::filesystem::create_directories(dir, ec);
123
234k
        if (ec) {
124
0
            return localfs_error(ec, fmt::format("failed to create {}", dir.native()));
125
0
        }
126
234k
    }
127
248k
    return Status::OK();
128
248k
}
129
130
260k
Status LocalFileSystem::delete_file_impl(const Path& file) {
131
260k
    VLOG_DEBUG << "delete file: " << file.native();
132
260k
    bool exists = true;
133
260k
    RETURN_IF_ERROR(exists_impl(file, &exists));
134
260k
    if (!exists) {
135
124k
        return Status::OK();
136
124k
    }
137
136k
    if (!std::filesystem::is_regular_file(file)) {
138
1
        return Status::InternalError("failed to delete {}, not a file", file.native());
139
1
    }
140
136k
    std::error_code ec;
141
136k
    std::filesystem::remove(file, ec);
142
136k
    if (ec) {
143
0
        return localfs_error(ec, fmt::format("failed to delete {}", file.native()));
144
0
    }
145
136k
    return Status::OK();
146
136k
}
147
148
12.6k
Status LocalFileSystem::delete_directory_impl(const Path& dir) {
149
12.6k
    VLOG_DEBUG << "delete directory: " << dir.native();
150
12.6k
    bool exists = true;
151
12.6k
    RETURN_IF_ERROR(exists_impl(dir, &exists));
152
12.6k
    if (!exists) {
153
985
        return Status::OK();
154
985
    }
155
11.7k
    if (!std::filesystem::is_directory(dir)) {
156
1
        return Status::InternalError("failed to delete {}, not a directory", dir.native());
157
1
    }
158
11.7k
    std::error_code ec;
159
11.7k
    std::filesystem::remove_all(dir, ec);
160
11.7k
    if (ec) {
161
0
        return localfs_error(ec, fmt::format("failed to delete {}", dir.native()));
162
0
    }
163
11.7k
    return Status::OK();
164
11.7k
}
165
166
24
Status LocalFileSystem::delete_directory_or_file(const Path& path) {
167
24
    FILESYSTEM_M(delete_directory_or_file_impl(path));
168
0
}
169
170
112k
Status LocalFileSystem::delete_empty_directory(const Path& dir) {
171
112k
    FILESYSTEM_M(delete_empty_directory_impl(dir));
172
0
}
173
174
112k
Status LocalFileSystem::delete_empty_directory_impl(const Path& dir) {
175
112k
    Path path;
176
112k
    RETURN_IF_ERROR(absolute_path(dir, path));
177
112k
    VLOG_DEBUG << "delete empty directory: " << path.native();
178
112k
    int ret = 0;
179
112k
    RETRY_ON_EINTR(ret, rmdir(path.c_str()));
180
112k
    if (ret != 0) {
181
3
        std::error_code ec(errno, std::generic_category());
182
3
        if (ec == std::errc::no_such_file_or_directory) {
183
1
            return Status::OK();
184
1
        }
185
2
        return localfs_error(ec, fmt::format("failed to delete empty directory {}", path.native()));
186
3
    }
187
112k
    return Status::OK();
188
112k
}
189
190
24
Status LocalFileSystem::delete_directory_or_file_impl(const Path& path) {
191
24
    bool is_dir;
192
24
    RETURN_IF_ERROR(is_directory(path, &is_dir));
193
22
    if (is_dir) {
194
1
        return delete_directory_impl(path);
195
21
    } else {
196
21
        return delete_file_impl(path);
197
21
    }
198
22
}
199
200
0
Status LocalFileSystem::batch_delete_impl(const std::vector<Path>& files) {
201
0
    for (auto& file : files) {
202
0
        RETURN_IF_ERROR(delete_file_impl(file));
203
0
    }
204
0
    return Status::OK();
205
0
}
206
207
2.16M
Status LocalFileSystem::exists_impl(const Path& path, bool* res) const {
208
2.16M
    std::error_code ec;
209
2.16M
    *res = std::filesystem::exists(path, ec);
210
2.16M
    if (ec) {
211
0
        return localfs_error(ec, fmt::format("failed to check exists {}", path.native()));
212
0
    }
213
2.16M
    return Status::OK();
214
2.16M
}
215
216
737k
Status LocalFileSystem::file_size_impl(const Path& file, int64_t* file_size) const {
217
737k
    std::error_code ec;
218
737k
    *file_size = std::filesystem::file_size(file, ec);
219
737k
    if (ec) {
220
4.73k
        return localfs_error(ec, fmt::format("failed to get file size {}", file.native()));
221
4.73k
    }
222
732k
    return Status::OK();
223
737k
}
224
225
130k
Status LocalFileSystem::directory_size(const Path& dir_path, size_t* dir_size) {
226
130k
    *dir_size = 0;
227
130k
    if (std::filesystem::exists(dir_path) && std::filesystem::is_directory(dir_path)) {
228
1.13M
        for (const auto& entry : std::filesystem::recursive_directory_iterator(dir_path)) {
229
1.13M
            if (std::filesystem::is_regular_file(entry)) {
230
6.00k
                *dir_size += std::filesystem::file_size(entry);
231
6.00k
            }
232
1.13M
        }
233
130k
        return Status::OK();
234
130k
    }
235
    // TODO(plat1ko): Use error code according to std::error_code
236
0
    return Status::InternalError("faile to get dir size {}", dir_path.native());
237
130k
}
238
239
Status LocalFileSystem::list_impl(const Path& dir, bool only_file, std::vector<FileInfo>* files,
240
843k
                                  bool* exists) {
241
843k
    RETURN_IF_ERROR(exists_impl(dir, exists));
242
843k
    if (!(*exists)) {
243
116k
        return Status::OK();
244
116k
    }
245
726k
    std::error_code ec;
246
726k
    try {
247
797k
        for (const auto& entry : std::filesystem::directory_iterator(dir, ec)) {
248
797k
            if (only_file && !entry.is_regular_file()) {
249
132
                continue;
250
132
            }
251
797k
            FileInfo file_info;
252
797k
            file_info.file_name = entry.path().filename();
253
797k
            file_info.is_file = entry.is_regular_file(ec);
254
797k
            if (ec) {
255
0
                break;
256
0
            }
257
797k
            if (file_info.is_file) {
258
210k
                file_info.file_size = entry.file_size(ec);
259
210k
                if (ec) {
260
1
                    break;
261
1
                }
262
210k
            }
263
797k
            files->push_back(std::move(file_info));
264
797k
        }
265
726k
    } catch (const std::filesystem::filesystem_error& e) {
266
        // although `directory_iterator(dir, ec)` does not throw an exception,
267
        // it may throw an exception during iterator++, so we need to catch the exception here
268
0
        return localfs_error(e.code(), fmt::format("failed to list {}, error message: {}",
269
0
                                                   dir.native(), e.what()));
270
0
    }
271
726k
    if (ec) {
272
2
        return localfs_error(ec, fmt::format("failed to list {}", dir.native()));
273
2
    }
274
726k
    return Status::OK();
275
726k
}
276
277
121k
Status LocalFileSystem::rename_impl(const Path& orig_name, const Path& new_name) {
278
18.4E
    VLOG_DEBUG << "rename file: " << orig_name.native() << " to " << new_name.native();
279
121k
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileSystem::rename",
280
121k
                                      Status::IOError("inject io error"));
281
121k
    std::error_code ec;
282
121k
    std::filesystem::rename(orig_name, new_name, ec);
283
121k
    if (ec) {
284
0
        return localfs_error(ec, fmt::format("failed to rename {} to {}", orig_name.native(),
285
0
                                             new_name.native()));
286
0
    }
287
121k
    return Status::OK();
288
121k
}
289
290
205
Status LocalFileSystem::link_file(const Path& src, const Path& dest) {
291
205
    FILESYSTEM_M(link_file_impl(src, dest));
292
0
}
293
294
205
Status LocalFileSystem::link_file_impl(const Path& src, const Path& dest) {
295
205
    VLOG_DEBUG << "link file: " << src.native() << " to " << dest.native();
296
205
    if (::link(src.c_str(), dest.c_str()) != 0) {
297
0
        return localfs_error(errno, fmt::format("failed to create hard link from {} to {}",
298
0
                                                src.native(), dest.native()));
299
0
    }
300
205
    return Status::OK();
301
205
}
302
303
1.55k
Status LocalFileSystem::canonicalize(const Path& path, std::string* real_path) {
304
1.55k
    std::error_code ec;
305
1.55k
    Path res = std::filesystem::canonical(path, ec);
306
1.55k
    if (ec) {
307
0
        return localfs_error(ec, fmt::format("failed to canonicalize {}", path.native()));
308
0
    }
309
1.55k
    *real_path = res.string();
310
1.55k
    return Status::OK();
311
1.55k
}
312
313
356
Status LocalFileSystem::is_directory(const Path& path, bool* res) {
314
356
    std::error_code ec;
315
356
    *res = std::filesystem::is_directory(path, ec);
316
356
    if (ec) {
317
4
        return localfs_error(ec, fmt::format("failed to canonicalize {}", path.native()));
318
4
    }
319
352
    return Status::OK();
320
356
}
321
322
448
Status LocalFileSystem::md5sum(const Path& file, std::string* md5sum) {
323
448
    FILESYSTEM_M(md5sum_impl(file, md5sum));
324
0
}
325
326
448
Status LocalFileSystem::md5sum_impl(const Path& file, std::string* md5sum) {
327
448
    int fd = open(file.c_str(), O_RDONLY);
328
448
    if (fd < 0) {
329
0
        return localfs_error(errno,
330
0
                             fmt::format("failed to open file for md5sum {}", file.native()));
331
0
    }
332
333
448
    struct stat statbuf;
334
448
    if (fstat(fd, &statbuf) < 0) {
335
0
        std::string err = errno_to_str();
336
0
        close(fd);
337
0
        return localfs_error(errno, fmt::format("failed to stat file {}", file.native()));
338
0
    }
339
448
    size_t file_len = statbuf.st_size;
340
448
    void* buf = mmap(nullptr, file_len, PROT_READ, MAP_SHARED, fd, 0);
341
342
448
    unsigned char result[MD5_DIGEST_LENGTH];
343
448
    MD5((unsigned char*)buf, file_len, result);
344
448
    munmap(buf, file_len);
345
346
448
    std::stringstream ss;
347
7.61k
    for (int32_t i = 0; i < MD5_DIGEST_LENGTH; i++) {
348
7.16k
        ss << std::setfill('0') << std::setw(2) << std::hex << (int)result[i];
349
7.16k
    }
350
448
    ss >> *md5sum;
351
352
448
    close(fd);
353
448
    return Status::OK();
354
448
}
355
356
Status LocalFileSystem::iterate_directory(const std::string& dir,
357
908
                                          const std::function<bool(const FileInfo& file)>& cb) {
358
908
    FILESYSTEM_M(iterate_directory_impl(dir, cb));
359
0
}
360
361
Status LocalFileSystem::iterate_directory_impl(
362
908
        const std::string& dir, const std::function<bool(const FileInfo& file)>& cb) {
363
908
    bool exists = true;
364
908
    std::vector<FileInfo> files;
365
908
    RETURN_IF_ERROR(list_impl(dir, false, &files, &exists));
366
908
    for (auto& file : files) {
367
65
        if (!cb(file)) {
368
2
            break;
369
2
        }
370
65
    }
371
908
    return Status::OK();
372
908
}
373
374
154k
Status LocalFileSystem::get_space_info(const Path& dir, size_t* capacity, size_t* available) {
375
154k
    FILESYSTEM_M(get_space_info_impl(dir, capacity, available));
376
0
}
377
378
154k
Status LocalFileSystem::get_space_info_impl(const Path& path, size_t* capacity, size_t* available) {
379
154k
    std::error_code ec;
380
154k
    std::filesystem::space_info info = std::filesystem::space(path, ec);
381
154k
    if (ec) {
382
16.0k
        return localfs_error(
383
16.0k
                ec, fmt::format("failed to get available space for path {}", path.native()));
384
16.0k
    }
385
138k
    *capacity = info.capacity;
386
138k
    *available = info.available;
387
138k
    return Status::OK();
388
154k
}
389
390
2
Status LocalFileSystem::copy_path(const Path& src, const Path& dest) {
391
2
    FILESYSTEM_M(copy_path_impl(src, dest));
392
0
}
393
394
2
Status LocalFileSystem::copy_path_impl(const Path& src, const Path& dest) {
395
2
    VLOG_DEBUG << "copy from " << src.native() << " to " << dest.native();
396
2
    std::error_code ec;
397
2
    std::filesystem::copy(src, dest, std::filesystem::copy_options::recursive, ec);
398
2
    if (ec) {
399
0
        return localfs_error(
400
0
                ec, fmt::format("failed to copy from {} to {}", src.native(), dest.native()));
401
0
    }
402
2
    return Status::OK();
403
2
}
404
405
460
bool LocalFileSystem::contain_path(const Path& parent_, const Path& sub_) {
406
460
    Path parent = parent_.lexically_normal();
407
460
    Path sub = sub_.lexically_normal();
408
460
    if (parent == sub) {
409
0
        return true;
410
0
    }
411
412
460
    if (parent.filename() == ".") {
413
0
        parent.remove_filename();
414
0
    }
415
416
    // We're also not interested in the file's name.
417
460
    if (sub.has_filename()) {
418
460
        sub.remove_filename();
419
460
    }
420
    // If dir has more components than file, then file can't possibly reside in dir.
421
460
    auto dir_len = std::distance(parent.begin(), parent.end());
422
460
    auto file_len = std::distance(sub.begin(), sub.end());
423
460
    if (dir_len > file_len) {
424
0
        return false;
425
0
    }
426
460
    auto p_it = parent.begin();
427
460
    auto s_it = sub.begin();
428
476
    for (; p_it != parent.end() && !p_it->string().empty(); ++p_it, ++s_it) {
429
16
        if (!(*p_it == *s_it)) {
430
0
            return false;
431
0
        }
432
16
    }
433
460
    return true;
434
460
}
435
436
156
bool LocalFileSystem::equal_or_sub_path(const Path& parent, const Path& child) {
437
156
    auto parent_path = parent.lexically_normal();
438
156
    auto child_path = child.lexically_normal();
439
156
    auto parent_it = parent_path.begin();
440
156
    auto child_it = child_path.begin();
441
1.21k
    for (; parent_it != parent_path.end() && child_it != child_path.end();
442
1.06k
         ++parent_it, ++child_it) {
443
1.06k
        if (*parent_it != *child_it) {
444
1
            return false;
445
1
        }
446
1.06k
    }
447
155
    return parent_it == parent_path.end();
448
156
}
449
450
2.22M
const std::shared_ptr<LocalFileSystem>& global_local_filesystem() {
451
2.22M
    static std::shared_ptr<LocalFileSystem> local_fs(new LocalFileSystem());
452
2.22M
    return local_fs;
453
2.22M
}
454
455
Status LocalFileSystem::canonicalize_local_file(const std::string& dir,
456
                                                const std::string& file_path,
457
456
                                                std::string* full_path) {
458
456
    const std::string absolute_path = dir + "/" + file_path;
459
456
    std::string canonical_path;
460
456
    RETURN_IF_ERROR(canonicalize(absolute_path, &canonical_path));
461
456
    if (!contain_path(dir, canonical_path)) {
462
0
        return Status::InvalidArgument("file path is not allowed: {}", canonical_path);
463
0
    }
464
465
456
    *full_path = canonical_path;
466
456
    return Status::OK();
467
456
}
468
469
451
Status LocalFileSystem::safe_glob(const std::string& path, std::vector<FileInfo>* res) {
470
451
    if (path.find("..") != std::string::npos) {
471
5
        return Status::InvalidArgument("can not contain '..' in path");
472
5
    }
473
446
    std::string full_path = config::user_files_secure_path + "/" + path;
474
446
    std::vector<std::string> files;
475
446
    RETURN_IF_ERROR(_glob(full_path, &files));
476
456
    for (auto& file : files) {
477
456
        FileInfo fi;
478
456
        fi.is_file = true;
479
456
        RETURN_IF_ERROR(canonicalize_local_file("", file, &(fi.file_name)));
480
456
        RETURN_IF_ERROR(file_size_impl(fi.file_name, &(fi.file_size)));
481
456
        res->push_back(std::move(fi));
482
456
    }
483
432
    return Status::OK();
484
432
}
485
486
446
Status LocalFileSystem::_glob(const std::string& pattern, std::vector<std::string>* res) {
487
446
    glob_t glob_result;
488
446
    memset(&glob_result, 0, sizeof(glob_result));
489
490
446
    int rc = glob(pattern.c_str(), GLOB_TILDE, NULL, &glob_result);
491
446
    if (rc != 0) {
492
14
        globfree(&glob_result);
493
14
        return Status::InternalError("failed to glob {}: {}", pattern, glob_err_to_str(rc));
494
14
    }
495
496
888
    for (size_t i = 0; i < glob_result.gl_pathc; ++i) {
497
456
        res->push_back(std::string(glob_result.gl_pathv[i]));
498
456
    }
499
500
432
    globfree(&glob_result);
501
432
    return Status::OK();
502
446
}
503
504
36
Status LocalFileSystem::permission(const Path& file, std::filesystem::perms prms) {
505
36
    FILESYSTEM_M(permission_impl(file, prms));
506
0
}
507
508
36
Status LocalFileSystem::permission_impl(const Path& file, std::filesystem::perms prms) {
509
36
    std::error_code ec;
510
36
    std::filesystem::permissions(file, prms, ec);
511
36
    if (ec) {
512
0
        return localfs_error(ec, fmt::format("failed to change file permission {}", file.native()));
513
0
    }
514
36
    return Status::OK();
515
36
}
516
517
3.43M
Status LocalFileSystem::convert_to_abs_path(const Path& input_path_str, Path& abs_path) {
518
    // valid path include:
519
    //   1. abc/def                         will return abc/def
520
    //   2. /abc/def                        will return /abc/def
521
    //   3. file:/abc/def                   will return /abc/def
522
    //   4. file://<authority>/abc/def      will return /abc/def
523
3.43M
    std::string path_str = input_path_str;
524
3.43M
    size_t slash = path_str.find('/');
525
3.43M
    if (slash == 0) {
526
3.35M
        abs_path = input_path_str;
527
3.35M
        return Status::OK();
528
3.35M
    }
529
530
    // Initialize scheme and authority
531
72.6k
    std::string scheme;
532
72.6k
    size_t start = 0;
533
534
    // Parse URI scheme
535
72.6k
    size_t colon = path_str.find(':');
536
72.6k
    if (colon != std::string::npos && (slash == std::string::npos || colon < slash)) {
537
        // Has a scheme
538
10
        scheme = path_str.substr(0, colon);
539
10
        if (scheme != "file") {
540
3
            return Status::InternalError(
541
3
                    "Only supports `file` type scheme, like 'file:///path', 'file:/path'.");
542
3
        }
543
7
        start = colon + 1;
544
7
    }
545
546
    // Parse URI authority, if any
547
72.6k
    if (path_str.compare(start, 2, "//") == 0 && path_str.length() - start > 2) {
548
        // Has authority
549
        // such as : path_str = "file://authority/abc/def"
550
        // and now : start = 5
551
6
        size_t next_slash = path_str.find('/', start + 2);
552
        // now : next_slash = 16
553
6
        if (next_slash == std::string::npos) {
554
1
            return Status::InternalError(
555
1
                    "This input string only has authority, but has no path information");
556
1
        }
557
        // We will skit authority
558
        // now : start = 16
559
5
        start = next_slash;
560
5
    }
561
562
    // URI path is the rest of the string
563
72.6k
    abs_path = path_str.substr(start);
564
72.6k
    return Status::OK();
565
72.6k
}
566
567
} // namespace doris::io