PR changed-lines coverage: 3.72% (11/296, 0 noise lines excluded) Uncovered changed code (with context): ================================================================================ src/Backups/BackupIO_URL.cpp ================================================================================ --- uncovered block 34-43 --- 32 | { 33 | HTTPHeaderEntries makeAuthHeaders(const Poco::Net::HTTPBasicCredentials & credentials) >> 34 | { >> 35 | if (credentials.getUsername().empty()) >> 36 | return {}; >> 37 | Poco::Net::HTTPRequest tmp_request; >> 38 | credentials.authenticate(tmp_request); >> 39 | String auth = tmp_request.get("Authorization", ""); >> 40 | if (auth.empty()) >> 41 | return {}; >> 42 | return {{"Authorization", auth}}; >> 43 | } 44 | } 45 | --- uncovered block 54-61 --- 52 | const WriteSettings & write_settings_, 53 | const ContextPtr & context_) >> 54 | : BackupReaderDefault(read_settings_, write_settings_, getLogger("BackupReaderURL")) >> 55 | , base_uri(uri_) >> 56 | , credentials(http_user_name, http_password) >> 57 | , timeouts(ConnectionTimeouts::getHTTPTimeouts(context_->getSettingsRef(), context_->getServerSettings())) >> 58 | , max_redirects(context_->getSettingsRef()[Setting::max_http_get_redirects]) >> 59 | , context(context_) >> 60 | { >> 61 | } 62 | 63 | BackupReaderURL::~BackupReaderURL() = default; --- uncovered block 63-63 --- 61 | } 62 | >> 63 | BackupReaderURL::~BackupReaderURL() = default; 64 | 65 | Poco::URI BackupReaderURL::getURIForFile(const String & file_name) const --- uncovered block 66-74 --- 64 | 65 | Poco::URI BackupReaderURL::getURIForFile(const String & file_name) const >> 66 | { >> 67 | Poco::URI uri = base_uri; >> 68 | String path = uri.getPath(); >> 69 | if (!path.empty() && path.back() != '/') >> 70 | path += '/'; >> 71 | path += file_name; >> 72 | uri.setPath(path); >> 73 | return uri; >> 74 | } 75 | 76 | bool BackupReaderURL::fileExists(const String & file_name) --- uncovered block 77-97 --- 75 | 76 | bool BackupReaderURL::fileExists(const String & file_name) >> 77 | { >> 78 | auto file_uri = getURIForFile(file_name); >> 79 | try >> 80 | { >> 81 | auto buf = BuilderRWBufferFromHTTP(file_uri) >> 82 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 83 | .withSettings(read_settings) >> 84 | .withTimeouts(timeouts) >> 85 | .withHostFilter(&context->getRemoteHostFilter()) >> 86 | .withRedirects(max_redirects) >> 87 | .create(credentials); >> 88 | buf->getFileInfo(); >> 89 | return true; >> 90 | } >> 91 | catch (const HTTPException & e) >> 92 | { >> 93 | if (e.getHTTPStatus() == Poco::Net::HTTPResponse::HTTP_NOT_FOUND) >> 94 | return false; >> 95 | throw; >> 96 | } >> 97 | } 98 | 99 | UInt64 BackupReaderURL::getFileSize(const String & file_name) --- uncovered block 100-113 --- 98 | 99 | UInt64 BackupReaderURL::getFileSize(const String & file_name) >> 100 | { >> 101 | auto file_uri = getURIForFile(file_name); >> 102 | auto buf = BuilderRWBufferFromHTTP(file_uri) >> 103 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 104 | .withSettings(read_settings) >> 105 | .withTimeouts(timeouts) >> 106 | .withHostFilter(&context->getRemoteHostFilter()) >> 107 | .withRedirects(max_redirects) >> 108 | .create(credentials); >> 109 | auto info = buf->getFileInfo(); >> 110 | if (!info.file_size) >> 111 | throw Exception(ErrorCodes::NETWORK_ERROR, "Cannot get file size from URL: {}", file_uri.toString()); >> 112 | return *info.file_size; >> 113 | } 114 | 115 | std::unique_ptr BackupReaderURL::readFile(const String & file_name) --- uncovered block 116-127 --- 114 | 115 | std::unique_ptr BackupReaderURL::readFile(const String & file_name) >> 116 | { >> 117 | auto file_uri = getURIForFile(file_name); >> 118 | auto buf = BuilderRWBufferFromHTTP(file_uri) >> 119 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 120 | .withSettings(read_settings) >> 121 | .withTimeouts(timeouts) >> 122 | .withHostFilter(&context->getRemoteHostFilter()) >> 123 | .withRedirects(max_redirects) >> 124 | .withDelayInit(false) >> 125 | .create(credentials); >> 126 | return std::make_unique(std::move(buf), file_uri.toString()); >> 127 | } 128 | 129 | --- uncovered block 138-146 --- 136 | const WriteSettings & write_settings_, 137 | const ContextPtr & context_) >> 138 | : BackupWriterDefault(read_settings_, write_settings_, getLogger("BackupWriterURL")) >> 139 | , base_uri(uri_) >> 140 | , credentials(http_user_name, http_password) >> 141 | , http_method(http_method_.empty() ? Poco::Net::HTTPRequest::HTTP_PUT : http_method_) >> 142 | , timeouts(ConnectionTimeouts::getHTTPTimeouts(context_->getSettingsRef(), context_->getServerSettings())) >> 143 | , max_redirects(context_->getSettingsRef()[Setting::max_http_get_redirects]) >> 144 | , context(context_) >> 145 | { >> 146 | } 147 | 148 | BackupWriterURL::~BackupWriterURL() = default; --- uncovered block 148-148 --- 146 | } 147 | >> 148 | BackupWriterURL::~BackupWriterURL() = default; 149 | 150 | Poco::URI BackupWriterURL::getURIForFile(const String & file_name) const --- uncovered block 151-159 --- 149 | 150 | Poco::URI BackupWriterURL::getURIForFile(const String & file_name) const >> 151 | { >> 152 | Poco::URI uri = base_uri; >> 153 | String path = uri.getPath(); >> 154 | if (!path.empty() && path.back() != '/') >> 155 | path += '/'; >> 156 | path += file_name; >> 157 | uri.setPath(path); >> 158 | return uri; >> 159 | } 160 | 161 | bool BackupWriterURL::fileExists(const String & file_name) --- uncovered block 162-182 --- 160 | 161 | bool BackupWriterURL::fileExists(const String & file_name) >> 162 | { >> 163 | auto file_uri = getURIForFile(file_name); >> 164 | try >> 165 | { >> 166 | auto buf = BuilderRWBufferFromHTTP(file_uri) >> 167 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 168 | .withSettings(read_settings) >> 169 | .withTimeouts(timeouts) >> 170 | .withHostFilter(&context->getRemoteHostFilter()) >> 171 | .withRedirects(max_redirects) >> 172 | .create(credentials); >> 173 | buf->getFileInfo(); >> 174 | return true; >> 175 | } >> 176 | catch (const HTTPException & e) >> 177 | { >> 178 | if (e.getHTTPStatus() == Poco::Net::HTTPResponse::HTTP_NOT_FOUND) >> 179 | return false; >> 180 | throw; >> 181 | } >> 182 | } 183 | 184 | UInt64 BackupWriterURL::getFileSize(const String & file_name) --- uncovered block 185-198 --- 183 | 184 | UInt64 BackupWriterURL::getFileSize(const String & file_name) >> 185 | { >> 186 | auto file_uri = getURIForFile(file_name); >> 187 | auto buf = BuilderRWBufferFromHTTP(file_uri) >> 188 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 189 | .withSettings(read_settings) >> 190 | .withTimeouts(timeouts) >> 191 | .withHostFilter(&context->getRemoteHostFilter()) >> 192 | .withRedirects(max_redirects) >> 193 | .create(credentials); >> 194 | auto info = buf->getFileInfo(); >> 195 | if (!info.file_size) >> 196 | throw Exception(ErrorCodes::NETWORK_ERROR, "Cannot get file size from URL: {}", file_uri.toString()); >> 197 | return *info.file_size; >> 198 | } 199 | 200 | std::unique_ptr BackupWriterURL::readFile(const String & file_name, size_t /*expected_file_size*/) --- uncovered block 201-211 --- 199 | 200 | std::unique_ptr BackupWriterURL::readFile(const String & file_name, size_t /*expected_file_size*/) >> 201 | { >> 202 | auto file_uri = getURIForFile(file_name); >> 203 | return BuilderRWBufferFromHTTP(file_uri) >> 204 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 205 | .withSettings(read_settings) >> 206 | .withTimeouts(timeouts) >> 207 | .withHostFilter(&context->getRemoteHostFilter()) >> 208 | .withRedirects(max_redirects) >> 209 | .withDelayInit(false) >> 210 | .create(credentials); >> 211 | } 212 | 213 | std::unique_ptr BackupWriterURL::writeFile(const String & file_name) --- uncovered block 214-222 --- 212 | 213 | std::unique_ptr BackupWriterURL::writeFile(const String & file_name) >> 214 | { >> 215 | auto file_uri = getURIForFile(file_name); >> 216 | return BuilderWriteBufferFromHTTP(file_uri) >> 217 | .withConnectionGroup(HTTPConnectionGroupType::HTTP) >> 218 | .withMethod(http_method) >> 219 | .withTimeouts(timeouts) >> 220 | .withAdditionalHeaders(makeAuthHeaders(credentials)) >> 221 | .create(); >> 222 | } 223 | 224 | void BackupWriterURL::copyFile(const String & destination, const String & source, size_t size) --- uncovered block 225-231 --- 223 | 224 | void BackupWriterURL::copyFile(const String & destination, const String & source, size_t size) >> 225 | { >> 226 | LOG_TRACE(log, "Copying file inside backup from {} to {}", source, destination); >> 227 | auto in = readFile(source, size); >> 228 | auto out = writeFile(destination); >> 229 | copyData(*in, *out, size); >> 230 | out->finalize(); >> 231 | } 232 | 233 | void BackupWriterURL::removeFile(const String & file_name) --- uncovered block 234-268 --- 232 | 233 | void BackupWriterURL::removeFile(const String & file_name) >> 234 | { >> 235 | auto file_uri = getURIForFile(file_name); >> 236 | try >> 237 | { >> 238 | auto session = makeHTTPSession(HTTPConnectionGroupType::HTTP, file_uri, timeouts); >> 239 | Poco::Net::HTTPRequest request( >> 240 | Poco::Net::HTTPRequest::HTTP_DELETE, >> 241 | file_uri.getPathAndQuery(), >> 242 | Poco::Net::HTTPMessage::HTTP_1_1); >> 243 | if (file_uri.getPort()) >> 244 | request.setHost(file_uri.getHost(), file_uri.getPort()); >> 245 | else >> 246 | request.setHost(file_uri.getHost()); >> 247 | if (!credentials.getUsername().empty()) >> 248 | credentials.authenticate(request); >> 249 | session->sendRequest(request); >> 250 | Poco::Net::HTTPResponse response; >> 251 | auto & response_stream = session->receiveResponse(response); >> 252 | std::string ignored_body; >> 253 | Poco::StreamCopier::copyToString(response_stream, ignored_body); /// Drain response body. >> 254 | auto status = response.getStatus(); >> 255 | if (status != Poco::Net::HTTPResponse::HTTP_OK >> 256 | && status != Poco::Net::HTTPResponse::HTTP_NO_CONTENT >> 257 | && status != Poco::Net::HTTPResponse::HTTP_NOT_FOUND) >> 258 | { >> 259 | LOG_WARNING( >> 260 | log, >> 261 | "HTTP DELETE returned unexpected status {} {} for URL {}", >> 262 | static_cast(status), >> 263 | response.getReason(), >> 264 | file_uri.toString()); >> 265 | } >> 266 | } >> 267 | catch (...) >> 268 | { 269 | LOG_WARNING(log, "Failed to remove file {} via HTTP DELETE: {}", file_name, getCurrentExceptionMessage(false)); 270 | } --- uncovered block 270-271 --- 268 | { 269 | LOG_WARNING(log, "Failed to remove file {} via HTTP DELETE: {}", file_name, getCurrentExceptionMessage(false)); >> 270 | } >> 271 | } 272 | 273 | } ================================================================================ src/Backups/registerBackupEngineURL.cpp ================================================================================ --- uncovered block 33-39 --- 31 | { 32 | String removeFileNameFromURL(String & url) >> 33 | { >> 34 | Poco::URI uri{url}; >> 35 | String path = uri.getPath(); >> 36 | size_t slash_pos = path.find_last_of('/'); >> 37 | String file_name = path.substr(slash_pos + 1); >> 38 | path.resize(slash_pos + 1); >> 39 | uri.setPath(path); 40 | url = uri.toString(); 41 | return file_name; WARNING: Failed to get start time for [Print Uncovered Code] - start time and duration won't be set