Coverage Report

Created: 2026-05-31 08:39

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
7
LocalFileSystem::LocalFileSystem() : FileSystem(FileSystem::TMP_FS_ID, FileSystemType::LOCAL) {}
54
55
2
LocalFileSystem::~LocalFileSystem() = default;
56
57
Status LocalFileSystem::create_file_impl(const Path& file, FileWriterPtr* writer,
58
136k
                                         const FileWriterOptions* opts) {
59
18.4E
    VLOG_DEBUG << "create file: " << file.native()
60
18.4E
               << ", sync_data: " << (opts ? opts->sync_file_data : true);
61
136k
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileSystem::create_file_impl",
62
136k
                                      Status::IOError("inject io error"));
63
    // O_TRUNC: if file already exists (last tmp), clear the content
64
136k
    int fd = ::open(file.c_str(), O_TRUNC | O_WRONLY | O_CREAT | O_CLOEXEC, 0666);
65
136k
    DBUG_EXECUTE_IF("LocalFileSystem.create_file_impl.open_file_failed", {
66
        // spare '.testfile' to make bad disk checker happy
67
136k
        auto sub_path = dp->param<std::string>("sub_path", "");
68
136k
        if ((sub_path.empty() && file.filename().compare(kTestFilePath)) ||
69
136k
            (!sub_path.empty() && file.native().find(sub_path) != std::string::npos)) {
70
136k
            ::close(fd);
71
136k
            fd = -1;
72
136k
            errno = EIO;
73
136k
            LOG(WARNING) << Status::IOError("debug open io error: {}", file.native());
74
136k
        }
75
136k
    });
76
136k
    if (-1 == fd) {
77
0
        return localfs_error(errno, fmt::format("failed to create file {}", file.native()));
78
0
    }
79
136k
    bool sync_data = opts != nullptr ? opts->sync_file_data : true;
80
136k
    *writer = std::make_unique<LocalFileWriter>(file, fd, sync_data);
81
136k
    return Status::OK();
82
136k
}
83
84
Status LocalFileSystem::open_file_impl(const Path& file, FileReaderSPtr* reader,
85
477k
                                       const FileReaderOptions* opts) {
86
477k
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileSystem::open_file_impl",
87
477k
                                      Status::IOError("inject io error"));
88
477k
    int64_t fsize = opts ? opts->file_size : -1;
89
477k
    if (fsize < 0) {
90
475k
        RETURN_IF_ERROR(file_size_impl(file, &fsize));
91
475k
    }
92
469k
    int fd = -1;
93
469k
    RETRY_ON_EINTR(fd, open(file.c_str(), O_RDONLY));
94
469k
    DBUG_EXECUTE_IF("LocalFileSystem.create_file_impl.open_file_failed", {
95
        // spare '.testfile' to make bad disk checker happy
96
469k
        auto sub_path = dp->param<std::string>("sub_path", "");
97
469k
        if ((sub_path.empty() && file.filename().compare(kTestFilePath)) ||
98
469k
            (!sub_path.empty() && file.native().find(sub_path) != std::string::npos)) {
99
469k
            ::close(fd);
100
469k
            fd = -1;
101
469k
            errno = EIO;
102
469k
            LOG(WARNING) << Status::IOError("debug open io error: {}", file.native());
103
469k
        }
104
469k
    });
105
469k
    if (fd < 0) {
106
0
        return localfs_error(errno, fmt::format("failed to open {}", file.native()));
107
0
    }
108
469k
    *reader = std::make_shared<LocalFileReader>(file, fsize, fd);
109
469k
    return Status::OK();
110
469k
}
111
112
242k
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
242k
    bool exists = true;
116
242k
    RETURN_IF_ERROR(exists_impl(dir, &exists));
117
242k
    if (exists && failed_if_exists) {
118
0
        return Status::AlreadyExist("failed to create {}, already exists", dir.native());
119
0
    }
120
242k
    if (!exists) {
121
231k
        std::error_code ec;
122
231k
        std::filesystem::create_directories(dir, ec);
123
231k
        if (ec) {
124
0
            return localfs_error(ec, fmt::format("failed to create {}", dir.native()));
125
0
        }
126
231k
    }
127
242k
    return Status::OK();
128
242k
}
129
130
252k
Status LocalFileSystem::delete_file_impl(const Path& file) {
131
252k
    VLOG_DEBUG << "delete file: " << file.native();
132
252k
    bool exists = true;
133
252k
    RETURN_IF_ERROR(exists_impl(file, &exists));
134
252k
    if (!exists) {
135
122k
        return Status::OK();
136
122k
    }
137
129k
    if (!std::filesystem::is_regular_file(file)) {
138
1
        return Status::InternalError("failed to delete {}, not a file", file.native());
139
1
    }
140
129k
    std::error_code ec;
141
129k
    std::filesystem::remove(file, ec);
142
129k
    if (ec) {
143
0
        return localfs_error(ec, fmt::format("failed to delete {}", file.native()));
144
0
    }
145
129k
    return Status::OK();
146
129k
}
147
148
9.23k
Status LocalFileSystem::delete_directory_impl(const Path& dir) {
149
9.23k
    VLOG_DEBUG << "delete directory: " << dir.native();
150
9.23k
    bool exists = true;
151
9.23k
    RETURN_IF_ERROR(exists_impl(dir, &exists));
152
9.23k
    if (!exists) {
153
991
        return Status::OK();
154
991
    }
155
8.24k
    if (!std::filesystem::is_directory(dir)) {
156
1
        return Status::InternalError("failed to delete {}, not a directory", dir.native());
157
1
    }
158
8.24k
    std::error_code ec;
159
8.24k
    std::filesystem::remove_all(dir, ec);
160
8.24k
    if (ec) {
161
0
        return localfs_error(ec, fmt::format("failed to delete {}", dir.native()));
162
0
    }
163
8.24k
    return Status::OK();
164
8.24k
}
165
166
20
Status LocalFileSystem::delete_directory_or_file(const Path& path) {
167
20
    FILESYSTEM_M(delete_directory_or_file_impl(path));
168
0
}
169
170
114k
Status LocalFileSystem::delete_empty_directory(const Path& dir) {
171
114k
    FILESYSTEM_M(delete_empty_directory_impl(dir));
172
0
}
173
174
114k
Status LocalFileSystem::delete_empty_directory_impl(const Path& dir) {
175
114k
    Path path;
176
114k
    RETURN_IF_ERROR(absolute_path(dir, path));
177
114k
    VLOG_DEBUG << "delete empty directory: " << path.native();
178
114k
    int ret = 0;
179
114k
    RETRY_ON_EINTR(ret, rmdir(path.c_str()));
180
114k
    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
114k
    return Status::OK();
188
114k
}
189
190
20
Status LocalFileSystem::delete_directory_or_file_impl(const Path& path) {
191
20
    bool is_dir;
192
20
    RETURN_IF_ERROR(is_directory(path, &is_dir));
193
20
    if (is_dir) {
194
1
        return delete_directory_impl(path);
195
19
    } else {
196
19
        return delete_file_impl(path);
197
19
    }
198
20
}
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
1.89M
Status LocalFileSystem::exists_impl(const Path& path, bool* res) const {
208
1.89M
    std::error_code ec;
209
1.89M
    *res = std::filesystem::exists(path, ec);
210
1.89M
    if (ec) {
211
0
        return localfs_error(ec, fmt::format("failed to check exists {}", path.native()));
212
0
    }
213
1.89M
    return Status::OK();
214
1.89M
}
215
216
491k
Status LocalFileSystem::file_size_impl(const Path& file, int64_t* file_size) const {
217
491k
    std::error_code ec;
218
491k
    *file_size = std::filesystem::file_size(file, ec);
219
491k
    if (ec) {
220
8.17k
        return localfs_error(ec, fmt::format("failed to get file size {}", file.native()));
221
8.17k
    }
222
482k
    return Status::OK();
223
491k
}
224
225
89.6k
Status LocalFileSystem::directory_size(const Path& dir_path, size_t* dir_size) {
226
89.6k
    *dir_size = 0;
227
89.6k
    if (std::filesystem::exists(dir_path) && std::filesystem::is_directory(dir_path)) {
228
992k
        for (const auto& entry : std::filesystem::recursive_directory_iterator(dir_path)) {
229
992k
            if (std::filesystem::is_regular_file(entry)) {
230
5.89k
                *dir_size += std::filesystem::file_size(entry);
231
5.89k
            }
232
992k
        }
233
89.6k
        return Status::OK();
234
89.6k
    }
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
89.6k
}
238
239
Status LocalFileSystem::list_impl(const Path& dir, bool only_file, std::vector<FileInfo>* files,
240
823k
                                  bool* exists) {
241
823k
    RETURN_IF_ERROR(exists_impl(dir, exists));
242
823k
    if (!(*exists)) {
243
117k
        return Status::OK();
244
117k
    }
245
706k
    std::error_code ec;
246
706k
    try {
247
760k
        for (const auto& entry : std::filesystem::directory_iterator(dir, ec)) {
248
760k
            if (only_file && !entry.is_regular_file()) {
249
132
                continue;
250
132
            }
251
759k
            FileInfo file_info;
252
759k
            file_info.file_name = entry.path().filename();
253
759k
            file_info.is_file = entry.is_regular_file(ec);
254
759k
            if (ec) {
255
0
                break;
256
0
            }
257
759k
            if (file_info.is_file) {
258
187k
                file_info.file_size = entry.file_size(ec);
259
187k
                if (ec) {
260
5
                    break;
261
5
                }
262
187k
            }
263
759k
            files->push_back(std::move(file_info));
264
759k
        }
265
706k
    } 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
706k
    if (ec) {
272
6
        return localfs_error(ec, fmt::format("failed to list {}", dir.native()));
273
6
    }
274
706k
    return Status::OK();
275
706k
}
276
277
120k
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
120k
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileSystem::rename",
280
120k
                                      Status::IOError("inject io error"));
281
120k
    std::error_code ec;
282
120k
    std::filesystem::rename(orig_name, new_name, ec);
283
120k
    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
120k
    return Status::OK();
288
120k
}
289
290
111
Status LocalFileSystem::link_file(const Path& src, const Path& dest) {
291
111
    FILESYSTEM_M(link_file_impl(src, dest));
292
0
}
293
294
111
Status LocalFileSystem::link_file_impl(const Path& src, const Path& dest) {
295
111
    VLOG_DEBUG << "link file: " << src.native() << " to " << dest.native();
296
111
    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
111
    return Status::OK();
301
111
}
302
303
867
Status LocalFileSystem::canonicalize(const Path& path, std::string* real_path) {
304
867
    std::error_code ec;
305
867
    Path res = std::filesystem::canonical(path, ec);
306
867
    if (ec) {
307
0
        return localfs_error(ec, fmt::format("failed to canonicalize {}", path.native()));
308
0
    }
309
867
    *real_path = res.string();
310
867
    return Status::OK();
311
867
}
312
313
192
Status LocalFileSystem::is_directory(const Path& path, bool* res) {
314
192
    std::error_code ec;
315
192
    *res = std::filesystem::is_directory(path, ec);
316
192
    if (ec) {
317
2
        return localfs_error(ec, fmt::format("failed to canonicalize {}", path.native()));
318
2
    }
319
190
    return Status::OK();
320
192
}
321
322
194
Status LocalFileSystem::md5sum(const Path& file, std::string* md5sum) {
323
194
    FILESYSTEM_M(md5sum_impl(file, md5sum));
324
0
}
325
326
194
Status LocalFileSystem::md5sum_impl(const Path& file, std::string* md5sum) {
327
194
    int fd = open(file.c_str(), O_RDONLY);
328
194
    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
194
    struct stat statbuf;
334
194
    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
194
    size_t file_len = statbuf.st_size;
340
194
    void* buf = mmap(nullptr, file_len, PROT_READ, MAP_SHARED, fd, 0);
341
342
194
    unsigned char result[MD5_DIGEST_LENGTH];
343
194
    MD5((unsigned char*)buf, file_len, result);
344
194
    munmap(buf, file_len);
345
346
194
    std::stringstream ss;
347
3.29k
    for (int32_t i = 0; i < MD5_DIGEST_LENGTH; i++) {
348
3.10k
        ss << std::setfill('0') << std::setw(2) << std::hex << (int)result[i];
349
3.10k
    }
350
194
    ss >> *md5sum;
351
352
194
    close(fd);
353
194
    return Status::OK();
354
194
}
355
356
Status LocalFileSystem::iterate_directory(const std::string& dir,
357
779
                                          const std::function<bool(const FileInfo& file)>& cb) {
358
779
    FILESYSTEM_M(iterate_directory_impl(dir, cb));
359
0
}
360
361
Status LocalFileSystem::iterate_directory_impl(
362
779
        const std::string& dir, const std::function<bool(const FileInfo& file)>& cb) {
363
779
    bool exists = true;
364
779
    std::vector<FileInfo> files;
365
779
    RETURN_IF_ERROR(list_impl(dir, false, &files, &exists));
366
779
    for (auto& file : files) {
367
65
        if (!cb(file)) {
368
2
            break;
369
2
        }
370
65
    }
371
779
    return Status::OK();
372
779
}
373
374
110k
Status LocalFileSystem::get_space_info(const Path& dir, size_t* capacity, size_t* available) {
375
110k
    FILESYSTEM_M(get_space_info_impl(dir, capacity, available));
376
0
}
377
378
110k
Status LocalFileSystem::get_space_info_impl(const Path& path, size_t* capacity, size_t* available) {
379
110k
    std::error_code ec;
380
110k
    std::filesystem::space_info info = std::filesystem::space(path, ec);
381
110k
    if (ec) {
382
15.8k
        return localfs_error(
383
15.8k
                ec, fmt::format("failed to get available space for path {}", path.native()));
384
15.8k
    }
385
94.8k
    *capacity = info.capacity;
386
94.8k
    *available = info.available;
387
94.8k
    return Status::OK();
388
110k
}
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
246
bool LocalFileSystem::contain_path(const Path& parent_, const Path& sub_) {
406
246
    Path parent = parent_.lexically_normal();
407
246
    Path sub = sub_.lexically_normal();
408
246
    if (parent == sub) {
409
0
        return true;
410
0
    }
411
412
246
    if (parent.filename() == ".") {
413
0
        parent.remove_filename();
414
0
    }
415
416
    // We're also not interested in the file's name.
417
246
    if (sub.has_filename()) {
418
246
        sub.remove_filename();
419
246
    }
420
    // If dir has more components than file, then file can't possibly reside in dir.
421
246
    auto dir_len = std::distance(parent.begin(), parent.end());
422
246
    auto file_len = std::distance(sub.begin(), sub.end());
423
246
    if (dir_len > file_len) {
424
0
        return false;
425
0
    }
426
246
    auto p_it = parent.begin();
427
246
    auto s_it = sub.begin();
428
262
    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
246
    return true;
434
246
}
435
436
82
bool LocalFileSystem::equal_or_sub_path(const Path& parent, const Path& child) {
437
82
    auto parent_path = parent.lexically_normal();
438
82
    auto child_path = child.lexically_normal();
439
82
    auto parent_it = parent_path.begin();
440
82
    auto child_it = child_path.begin();
441
627
    for (; parent_it != parent_path.end() && child_it != child_path.end();
442
546
         ++parent_it, ++child_it) {
443
546
        if (*parent_it != *child_it) {
444
1
            return false;
445
1
        }
446
546
    }
447
81
    return parent_it == parent_path.end();
448
82
}
449
450
1.61M
const std::shared_ptr<LocalFileSystem>& global_local_filesystem() {
451
1.61M
    static std::shared_ptr<LocalFileSystem> local_fs(new LocalFileSystem());
452
1.61M
    return local_fs;
453
1.61M
}
454
455
Status LocalFileSystem::canonicalize_local_file(const std::string& dir,
456
                                                const std::string& file_path,
457
242
                                                std::string* full_path) {
458
242
    const std::string absolute_path = dir + "/" + file_path;
459
242
    std::string canonical_path;
460
242
    RETURN_IF_ERROR(canonicalize(absolute_path, &canonical_path));
461
242
    if (!contain_path(dir, canonical_path)) {
462
0
        return Status::InvalidArgument("file path is not allowed: {}", canonical_path);
463
0
    }
464
465
242
    *full_path = canonical_path;
466
242
    return Status::OK();
467
242
}
468
469
241
Status LocalFileSystem::safe_glob(const std::string& path, std::vector<FileInfo>* res) {
470
241
    if (path.find("..") != std::string::npos) {
471
3
        return Status::InvalidArgument("can not contain '..' in path");
472
3
    }
473
238
    std::string full_path = config::user_files_secure_path + "/" + path;
474
238
    std::vector<std::string> files;
475
238
    RETURN_IF_ERROR(_glob(full_path, &files));
476
242
    for (auto& file : files) {
477
242
        FileInfo fi;
478
242
        fi.is_file = true;
479
242
        RETURN_IF_ERROR(canonicalize_local_file("", file, &(fi.file_name)));
480
242
        RETURN_IF_ERROR(file_size_impl(fi.file_name, &(fi.file_size)));
481
242
        res->push_back(std::move(fi));
482
242
    }
483
228
    return Status::OK();
484
228
}
485
486
238
Status LocalFileSystem::_glob(const std::string& pattern, std::vector<std::string>* res) {
487
238
    glob_t glob_result;
488
238
    memset(&glob_result, 0, sizeof(glob_result));
489
490
238
    int rc = glob(pattern.c_str(), GLOB_TILDE, NULL, &glob_result);
491
238
    if (rc != 0) {
492
10
        globfree(&glob_result);
493
10
        return Status::InternalError("failed to glob {}: {}", pattern, glob_err_to_str(rc));
494
10
    }
495
496
470
    for (size_t i = 0; i < glob_result.gl_pathc; ++i) {
497
242
        res->push_back(std::string(glob_result.gl_pathv[i]));
498
242
    }
499
500
228
    globfree(&glob_result);
501
228
    return Status::OK();
502
238
}
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
2.89M
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
2.89M
    std::string path_str = input_path_str;
524
2.89M
    size_t slash = path_str.find('/');
525
2.89M
    if (slash == 0) {
526
2.82M
        abs_path = input_path_str;
527
2.82M
        return Status::OK();
528
2.82M
    }
529
530
    // Initialize scheme and authority
531
72.8k
    std::string scheme;
532
72.8k
    size_t start = 0;
533
534
    // Parse URI scheme
535
72.8k
    size_t colon = path_str.find(':');
536
72.8k
    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.8k
    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.8k
    abs_path = path_str.substr(start);
564
72.8k
    return Status::OK();
565
72.8k
}
566
567
} // namespace doris::io