From ccb9e7abaf5de02c9938f1d7f7238316909ec165 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 10 Jul 2021 13:55:38 +0200 Subject: [PATCH] Touch up secondary storage code slightly --- doc/MANUAL.adoc | 12 ++++++------ src/storage/secondary/FileStorage.cpp | 2 +- src/storage/secondary/FileStorage.hpp | 2 +- src/storage/secondary/HttpStorage.cpp | 12 ++++-------- src/storage/secondary/HttpStorage.hpp | 3 ++- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index fe5f7cdb7..f7386d3e3 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -936,8 +936,8 @@ Optional attributes: URL format: `http://HOST[:PORT][/PATH]` -This backend stores data in an HTTP compatible server. The required HTTP -methods are `GET`, `PUT` and `DELETE`. +This backend stores data in an HTTP-compatible server. The required HTTP methods +are `GET`, `PUT` and `DELETE`. Note that ccache will not perform any cleanup of the HTTP storage. @@ -948,10 +948,10 @@ Examples: Known issues and limitations: -* URLs containing IPv6 addresses like `http://[::1]/` are not supported -* There are no HTTP timeouts implemented or configured -* Authentication is not yet supported -* HTTPS is not yet supported +* There are no HTTP timeouts implemented or configured. +* Authentication is not yet supported. +* HTTPS is not yet supported. +* URLs containing IPv6 addresses like `http://[::1]/` are not supported. == Cache size management diff --git a/src/storage/secondary/FileStorage.cpp b/src/storage/secondary/FileStorage.cpp index 3c0e5985b..ab6b2fd73 100644 --- a/src/storage/secondary/FileStorage.cpp +++ b/src/storage/secondary/FileStorage.cpp @@ -105,7 +105,7 @@ FileStorage::get(const Digest& key) nonstd::expected FileStorage::put(const Digest& key, const std::string& value, - bool only_if_missing) + const bool only_if_missing) { const auto path = get_entry_path(key); diff --git a/src/storage/secondary/FileStorage.hpp b/src/storage/secondary/FileStorage.hpp index ac4271a84..0703e1be3 100644 --- a/src/storage/secondary/FileStorage.hpp +++ b/src/storage/secondary/FileStorage.hpp @@ -28,7 +28,7 @@ namespace storage { namespace secondary { -class FileStorage : public storage::SecondaryStorage +class FileStorage : public SecondaryStorage { public: FileStorage(const Url& url, const AttributeMap& attributes); diff --git a/src/storage/secondary/HttpStorage.cpp b/src/storage/secondary/HttpStorage.cpp index 5c4bd21ab..7ec99c348 100644 --- a/src/storage/secondary/HttpStorage.cpp +++ b/src/storage/secondary/HttpStorage.cpp @@ -35,7 +35,7 @@ namespace secondary { namespace { nonstd::string_view -to_string(httplib::Error error) +to_string(const httplib::Error error) { using httplib::Error; @@ -76,8 +76,7 @@ get_url_port(const Url& url) { if (!url.port().empty()) { return Util::parse_unsigned(url.port(), 1, 65535, "port"); - } - if (url.scheme() == "http") { + } else if (url.scheme() == "http") { return 80; } else { throw Error("Unknown scheme: {}", url.scheme()); @@ -112,7 +111,6 @@ nonstd::expected, SecondaryStorage::Error> HttpStorage::get(const Digest& key) { const auto url_path = get_entry_path(key); - const auto result = m_http_client->Get(url_path.c_str()); if (result.error() != httplib::Error::Success || !result) { @@ -134,7 +132,7 @@ HttpStorage::get(const Digest& key) nonstd::expected HttpStorage::put(const Digest& key, const std::string& value, - bool only_if_missing) + const bool only_if_missing) { const auto url_path = get_entry_path(key); @@ -157,8 +155,7 @@ HttpStorage::put(const Digest& key, } } - const auto content_type = "application/octet-stream"; - + static const auto content_type = "application/octet-stream"; const auto result = m_http_client->Put( url_path.c_str(), value.data(), value.size(), content_type); @@ -184,7 +181,6 @@ nonstd::expected HttpStorage::remove(const Digest& key) { const auto url_path = get_entry_path(key); - const auto result = m_http_client->Delete(url_path.c_str()); if (result.error() != httplib::Error::Success || !result) { diff --git a/src/storage/secondary/HttpStorage.hpp b/src/storage/secondary/HttpStorage.hpp index e0ea61b8f..f9d46ba23 100644 --- a/src/storage/secondary/HttpStorage.hpp +++ b/src/storage/secondary/HttpStorage.hpp @@ -25,6 +25,7 @@ #include class Url; + namespace httplib { class Client; } @@ -32,7 +33,7 @@ class Client; namespace storage { namespace secondary { -class HttpStorage : public storage::SecondaryStorage +class HttpStorage : public SecondaryStorage { public: HttpStorage(const Url& url, const AttributeMap& attributes); -- 2.47.3