/Users/deen/code/yugabyte-db/src/yb/util/path_util.h
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 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | // Utility methods for dealing with file paths. |
33 | | #ifndef YB_UTIL_PATH_UTIL_H |
34 | | #define YB_UTIL_PATH_UTIL_H |
35 | | |
36 | | #include <string> |
37 | | |
38 | | #include "yb/util/status_fwd.h" |
39 | | |
40 | | namespace yb { |
41 | | |
42 | | class Env; |
43 | | |
44 | | // Appends path segments with the appropriate path separator, if necessary. |
45 | | void AppendPathSegments(std::string* out, const std::string &b); |
46 | | |
47 | | template <class... Args> |
48 | 466k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { |
49 | 466k | AppendPathSegments(out, a); |
50 | 466k | AppendPathSegments(out, std::forward<Args>(args)...); |
51 | 466k | } void yb::AppendPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 48 | 300k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 300k | AppendPathSegments(out, a); | 50 | 300k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 300k | } |
void yb::AppendPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 48 | 150k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 150k | AppendPathSegments(out, a); | 50 | 150k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 150k | } |
void yb::AppendPathSegments<char const*&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*&) Line | Count | Source | 48 | 3.83k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 3.83k | AppendPathSegments(out, a); | 50 | 3.83k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 3.83k | } |
void yb::AppendPathSegments<char const (&) [9]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [9]) Line | Count | Source | 48 | 4.01k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 4.01k | AppendPathSegments(out, a); | 50 | 4.01k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 4.01k | } |
void yb::AppendPathSegments<char const (&) [4], char const (&) [14]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [4], char const (&) [14]) Line | Count | Source | 48 | 1.99k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 1.99k | AppendPathSegments(out, a); | 50 | 1.99k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 1.99k | } |
void yb::AppendPathSegments<char const (&) [14]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [14]) Line | Count | Source | 48 | 1.99k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 1.99k | AppendPathSegments(out, a); | 50 | 1.99k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 1.99k | } |
void yb::AppendPathSegments<char const (&) [7]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [7]) Line | Count | Source | 48 | 4.02k | void AppendPathSegments(std::string* out, const std::string& a, Args&&... args) { | 49 | 4.02k | AppendPathSegments(out, a); | 50 | 4.02k | AppendPathSegments(out, std::forward<Args>(args)...); | 51 | 4.02k | } |
|
52 | | |
53 | | template <class... Args> |
54 | 21.1M | std::string JoinPathSegments(const std::string& a, Args&&... args) { |
55 | 21.1M | std::string result = a; |
56 | 21.1M | AppendPathSegments(&result, std::forward<Args>(args)...); |
57 | 21.1M | return result; |
58 | 21.1M | } std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) Line | Count | Source | 54 | 196k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 196k | std::string result = a; | 56 | 196k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 196k | return result; | 58 | 196k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 54 | 9.29M | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 9.29M | std::string result = a; | 56 | 9.29M | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 9.29M | return result; | 58 | 9.29M | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) Line | Count | Source | 54 | 162k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 162k | std::string result = a; | 56 | 162k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 162k | return result; | 58 | 162k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const*&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*&) Line | Count | Source | 54 | 403k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 403k | std::string result = a; | 56 | 403k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 403k | return result; | 58 | 403k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 54 | 150k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 150k | std::string result = a; | 56 | 150k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 150k | return result; | 58 | 150k | } |
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const*&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 54 | 150k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 150k | std::string result = a; | 56 | 150k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 150k | return result; | 58 | 150k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [4]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [4]) Line | Count | Source | 54 | 10.9k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 10.9k | std::string result = a; | 56 | 10.9k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 10.9k | return result; | 58 | 10.9k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [6]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [6]) Line | Count | Source | 54 | 1.97k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 1.97k | std::string result = a; | 56 | 1.97k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 1.97k | return result; | 58 | 1.97k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [7]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [7]) Line | Count | Source | 54 | 198 | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 198 | std::string result = a; | 56 | 198 | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 198 | return result; | 58 | 198 | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const*&, char const*&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*&, char const*&) Line | Count | Source | 54 | 3.83k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 3.83k | std::string result = a; | 56 | 3.83k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 3.83k | return result; | 58 | 3.83k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [16]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [16]) Line | Count | Source | 54 | 2.00k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 2.00k | std::string result = a; | 56 | 2.00k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 2.00k | return result; | 58 | 2.00k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [13]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [13]) Line | Count | Source | 54 | 46.0k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 46.0k | std::string result = a; | 56 | 46.0k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 46.0k | return result; | 58 | 46.0k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [14]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [14]) Line | Count | Source | 54 | 2.00k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 2.00k | std::string result = a; | 56 | 2.00k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 2.00k | return result; | 58 | 2.00k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [9]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [9]) Line | Count | Source | 54 | 74.0k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 74.0k | std::string result = a; | 56 | 74.0k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 74.0k | return result; | 58 | 74.0k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [4], char const (&) [9]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [4], char const (&) [9]) Line | Count | Source | 54 | 4.01k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 4.01k | std::string result = a; | 56 | 4.01k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 4.01k | return result; | 58 | 4.01k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [3], char const (&) [4], char const (&) [14]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [3], char const (&) [4], char const (&) [14]) Line | Count | Source | 54 | 1.99k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 1.99k | std::string result = a; | 56 | 1.99k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 1.99k | return result; | 58 | 1.99k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [4], char const (&) [7]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [4], char const (&) [7]) Line | Count | Source | 54 | 4.02k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 4.02k | std::string result = a; | 56 | 4.02k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 4.02k | return result; | 58 | 4.02k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [15]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [15]) Line | Count | Source | 54 | 2.84M | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 2.84M | std::string result = a; | 56 | 2.84M | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 2.84M | return result; | 58 | 2.84M | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [12]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [12]) Line | Count | Source | 54 | 1.77M | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 1.77M | std::string result = a; | 56 | 1.77M | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 1.77M | return result; | 58 | 1.77M | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [8]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [8]) Line | Count | Source | 54 | 5.97M | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 5.97M | std::string result = a; | 56 | 5.97M | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 5.97M | return result; | 58 | 5.97M | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [11]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [11]) Line | Count | Source | 54 | 15 | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 15 | std::string result = a; | 56 | 15 | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 15 | return result; | 58 | 15 | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [5]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [5]) Line | Count | Source | 54 | 2.02k | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 2.02k | std::string result = a; | 56 | 2.02k | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 2.02k | return result; | 58 | 2.02k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::JoinPathSegments<char const (&) [17]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [17]) Line | Count | Source | 54 | 1 | std::string JoinPathSegments(const std::string& a, Args&&... args) { | 55 | 1 | std::string result = a; | 56 | 1 | AppendPathSegments(&result, std::forward<Args>(args)...); | 57 | 1 | return result; | 58 | 1 | } |
|
59 | | |
60 | | // Return the enclosing directory of path. |
61 | | // This is like dirname(3) but for C++ strings. |
62 | | std::string DirName(const std::string& path); |
63 | | |
64 | | // Return the terminal component of a path. |
65 | | // This is like basename(3) but for C++ strings. |
66 | | std::string BaseName(const std::string& path); |
67 | | |
68 | | // We ask the user to specify just a set of top level dirs where we can place data. However, |
69 | | // under those, we create our own structure, which includes one level worth of generic suffix |
70 | | // and another level under that splitting by server type (master vs tserver). |
71 | | std::string GetYbDataPath(const std::string& root); |
72 | | std::string GetServerTypeDataPath(const std::string& root, const std::string& server_type); |
73 | | |
74 | | // For the user specified root dirs, setup the two level hierarchy below it and report the final |
75 | | // path as well as whether we created the final path or not. |
76 | | Status SetupRootDir( |
77 | | Env* env, const std::string& root, const std::string& server_type, std::string* out_dir, |
78 | | bool* created); |
79 | | |
80 | | // Tests whether a given path allows creation of temporary files with O_DIRECT given a |
81 | | // environment variable. |
82 | | Status CheckODirectTempFileCreationInDir(Env* env, const std::string& dir_path); |
83 | | |
84 | | } // namespace yb |
85 | | #endif /* YB_UTIL_PATH_UTIL_H */ |