| 133 | } |
| 134 | |
| 135 | Result<std::string> PathFromUriHelper(const std::string& uri_string, |
| 136 | std::vector<std::string> supported_schemes, |
| 137 | bool accept_local_paths, |
| 138 | AuthorityHandlingBehavior authority_handling) { |
| 139 | if (internal::DetectAbsolutePath(uri_string)) { |
| 140 | if (accept_local_paths) { |
| 141 | // Normalize the path and remove any trailing slash |
| 142 | return std::string( |
| 143 | internal::RemoveTrailingSlash(ToSlashes(uri_string), /*preserve_root=*/true)); |
| 144 | } |
| 145 | return Status::Invalid( |
| 146 | "The filesystem is not capable of loading local paths. Expected a URI but " |
| 147 | "received ", |
| 148 | uri_string); |
| 149 | } |
| 150 | Uri uri; |
| 151 | ARROW_RETURN_NOT_OK(uri.Parse(uri_string)); |
| 152 | const auto scheme = uri.scheme(); |
| 153 | if (std::find(supported_schemes.begin(), supported_schemes.end(), scheme) == |
| 154 | supported_schemes.end()) { |
| 155 | std::string expected_schemes = |
| 156 | ::arrow::internal::JoinStrings(supported_schemes, ", "); |
| 157 | return Status::Invalid("The filesystem expected a URI with one of the schemes (", |
| 158 | expected_schemes, ") but received ", uri_string); |
| 159 | } |
| 160 | std::string host = uri.host(); |
| 161 | std::string path = uri.path(); |
| 162 | if (host.empty()) { |
| 163 | // Just a path, may be absolute or relative, only allow relative paths if local |
| 164 | if (path[0] == '/') { |
| 165 | return std::string(internal::RemoveTrailingSlash(path)); |
| 166 | } |
| 167 | if (accept_local_paths) { |
| 168 | return std::string(internal::RemoveTrailingSlash(path)); |
| 169 | } |
| 170 | return Status::Invalid("The filesystem does not support relative paths. Received ", |
| 171 | uri_string); |
| 172 | } |
| 173 | if (authority_handling == AuthorityHandlingBehavior::kDisallow) { |
| 174 | return Status::Invalid( |
| 175 | "The filesystem does not support the authority (host) component of a URI. " |
| 176 | "Received ", |
| 177 | uri_string); |
| 178 | } |
| 179 | if (path[0] != '/') { |
| 180 | // This should not be possible |
| 181 | return Status::Invalid( |
| 182 | "The provided URI has a host component but a relative path which is not " |
| 183 | "supported. " |
| 184 | "Received ", |
| 185 | uri_string); |
| 186 | } |
| 187 | switch (authority_handling) { |
| 188 | case AuthorityHandlingBehavior::kPrepend: |
| 189 | return std::string(internal::RemoveTrailingSlash(host + path)); |
| 190 | case AuthorityHandlingBehavior::kWindows: |
| 191 | return std::string(internal::RemoveTrailingSlash("//" + host + path)); |
| 192 | case AuthorityHandlingBehavior::kIgnore: |
no test coverage detected