From 7c2e33949b608dde617859d4da2e920a0842097e Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 25 Oct 2019 05:59:13 +0200 Subject: [PATCH 01/10] Add more warnings to compiler flags. --- CMakeLists.txt | 67 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a2a665..8049415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,23 +29,56 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -set(DEBUG_CXXFLAGS - "-Wall" - "-Wextra" - "-Wpedantic" - "-ftrapv" - "-fsanitize=undefined" - "-g" - "-Og" - "-fno-omit-frame-pointer") -set(DEBUG_LDFLAGS - "-fsanitize=undefined") -add_compile_options("$<$:${DEBUG_CXXFLAGS}>") -# add_link_options was introduced in version 3.13. -if(${CMAKE_VERSION} VERSION_LESS 3.13) - set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}") -else() - add_link_options("$<$:${DEBUG_LDFLAGS}>") +set(DEBUG_CXXFLAGS "") +# GCC >= 5.0 or Clang >= 5.0 is assumed. +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + list(APPEND DEBUG_CXXFLAGS + "-Wall" + "-Wextra" + "-Wpedantic" + "-Wuninitialized" + "-Wshadow" + "-Wnon-virtual-dtor" + "-Wconversion" + "-Wsign-conversion" + "-Wold-style-cast" + "-Wzero-as-null-pointer-constant" + # "-Wmissing-declarations" + "-Wcast-align" + "-Wunused" + "-Woverloaded-virtual" + "-Wdouble-promotion" + "-Wformat=2" + "-ftrapv" + "-fsanitize=undefined" + "-g" + "-Og" + "-fno-omit-frame-pointer") + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + list(APPEND DEBUG_CXXFLAGS + "-Wlogical-op" + "-Wuseless-cast") + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6") + list(APPEND DEBUG_CXXFLAGS + "-Wmisleading-indentation" + "-Wduplicated-cond" + "-Wnull-dereference") + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7") + list(APPEND DEBUG_CXXFLAGS + "-Wduplicated-branches") + endif() + endif() + endif() + + set(DEBUG_LDFLAGS + "-fsanitize=undefined") + add_compile_options("$<$:${DEBUG_CXXFLAGS}>") + # add_link_options was introduced in version 3.13. + if(${CMAKE_VERSION} VERSION_LESS 3.13) + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}") + else() + add_link_options("$<$:${DEBUG_LDFLAGS}>") + endif() endif() add_subdirectory(src) From f8040f480308b5dacc0a5ff81912282e45cf6de1 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 25 Oct 2019 06:00:36 +0200 Subject: [PATCH 02/10] Make type conversions explicit. --- .../native-wrapper/remwharead_wrapper.cpp | 2 +- src/lib/uri.cpp | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index 060e7ea..172f2b1 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -55,7 +55,7 @@ const string read_input() void send_message(const string &message) { - const uint32_t length = message.length() + 2; + const uint32_t length = static_cast(message.length() + 2); cout.write(reinterpret_cast(&length), sizeof(uint32_t)); cout << '"' << message << '"'; } diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp index bb2cf18..a976718 100644 --- a/src/lib/uri.cpp +++ b/src/lib/uri.cpp @@ -45,6 +45,7 @@ using std::vector; using std::cerr; using std::endl; using std::move; +using std::uint32_t; using Poco::Net::HTTPClientSession; using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPRequest; @@ -92,12 +93,13 @@ void URI::set_proxy() proxy.host = matches[3]; if (!matches[4].empty()) { - const std::uint32_t &port = std::stoul(matches[4]); + // NOLINTNEXTLINE(google-runtime-lint) - Need to use same as stoul. + const unsigned long port = std::stoul(matches[4]); if (port > 65535) { throw std::invalid_argument("Proxy port number out of range"); } - proxy.port = port; + proxy.port = static_cast(port); } HTTPClientSession::setGlobalProxyConfig(proxy); } @@ -331,11 +333,11 @@ string URI::unescape_html(string html) // 'x' in front of the number means it's hexadecimal, else decimal. if (matches[1].length != 0) { - codepoint = std::stoi(number, nullptr, 16); + codepoint = static_cast(std::stoul(number, nullptr, 16)); } else { - codepoint = std::stoi(number, nullptr, 10); + codepoint = static_cast(std::stoi(number, nullptr, 10)); } const string unicode = u8c.to_bytes(codepoint); html.replace(matches[0].offset, matches[0].length, unicode); @@ -664,8 +666,14 @@ string URI::cut_text(const string &text, const uint16_t n_chars) const { constexpr char suffix[] = " […]"; constexpr auto suffix_len = std::end(suffix) - std::begin(suffix) - 1; + if (n_chars <= suffix_len) + { + throw std::invalid_argument("n_chars has to be greater than " + + std::to_string(suffix_len)); + } - const size_t pos = text.rfind(' ', n_chars - suffix_len); + const size_t pos = + text.rfind(' ', static_cast(n_chars - suffix_len)); return text.substr(0, pos) + suffix; } From d821a9310f52f7b82fec30c51c7ee900a97db73f Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 25 Oct 2019 06:00:56 +0200 Subject: [PATCH 03/10] Add virtual destructor to ExportBase. --- include/export/export.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/export/export.hpp b/include/export/export.hpp index 98f0259..5802a1c 100644 --- a/include/export/export.hpp +++ b/include/export/export.hpp @@ -46,6 +46,7 @@ public: */ explicit ExportBase(const list &entries, ostream &out = cout); + virtual ~ExportBase() = default; /*! * @brief Print output to std::ostream. From cae1d99f9a7813b7c893c95cd78925e998965cb8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 25 Oct 2019 06:01:14 +0200 Subject: [PATCH 04/10] Add missing header. --- src/lib/time.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/time.cpp b/src/lib/time.cpp index 4007bf3..4f037eb 100644 --- a/src/lib/time.cpp +++ b/src/lib/time.cpp @@ -14,6 +14,7 @@ * along with this program. If not, see . */ +#include "time.hpp" #include "sqlite.hpp" #include #include From e1ee5d7b37c7d4fefe5458c2811538e1b5f900bb Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 05:05:17 +0100 Subject: [PATCH 05/10] Remove dependency on libxdg-basedir and pkg-config. --- .drone.yml | 10 +++++----- README.adoc | 6 +----- cmake/packages.cmake | 2 +- cmake/remwhareadConfig.cmake.in | 2 -- pkg-config/remwharead.pc.in | 2 +- src/lib/CMakeLists.txt | 4 +--- src/lib/sqlite.cpp | 28 +++++++++++++++++++++++----- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.drone.yml b/.drone.yml index 9c358f0..4e237d4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -24,7 +24,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy g++ cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy g++-7 cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES -DWITH_TESTS=YES .. - make VERBOSE=1 @@ -52,7 +52,7 @@ steps: - gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add - - apt-get update -q - apt-get install -qy -t bionic g++-9 - - apt-get install -qy cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES .. - make VERBOSE=1 @@ -71,7 +71,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy clang-6.0 cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy clang-6.0 cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES .. - make VERBOSE=1 @@ -90,7 +90,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy clang cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy clang cmake libpoco-dev asciidoc catch - rm -rf build && mkdir -p build && cd build - cmake -DWITH_MOZILLA=YES .. - make VERBOSE=1 @@ -140,7 +140,7 @@ steps: - rm /etc/apt/apt.conf.d/docker-clean - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - - apt-get install -qy g++ cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc catch + - apt-get install -qy g++ cmake libpoco-dev asciidoc catch - apt-get install -qy build-essential file zip - rm -rf build && mkdir -p build && cd build - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES -DMOZILLA_NMH_DIR="lib/mozilla/native-messaging-hosts" -DWITH_DEB=YES .. diff --git a/README.adoc b/README.adoc index efbe359..141cbe9 100644 --- a/README.adoc +++ b/README.adoc @@ -12,8 +12,6 @@ :uri-gcc: https://gcc.gnu.org/ :uri-clang: https://clang.llvm.org/ :uri-cmake: https://cmake.org/ -:uri-pkgconfig: https://pkgconfig.freedesktop.org/wiki/ -:uri-libxdg-basedir: http://repo.or.cz/w/libxdg-basedir.git :uri-poco: https://pocoproject.org/ :uri-asciidoc: http://asciidoc.org/ :uri-catch: https://github.com/catchorg/Catch2 @@ -80,8 +78,6 @@ only. * Tested OS: Linux * C++ compiler (tested: {uri-gcc}[gcc] 8/9, {uri-clang}[clang] 6/7) * {uri-cmake}[cmake] (at least: 3.6) -* {uri-pkgconfig}[pkgconfig] (tested: 0.29) -* {uri-libxdg-basedir}[libxdg-basedir] (tested: 1.2) * {uri-poco}[POCO] (tested: 1.9 / 1.7) * Optional: ** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6) @@ -93,7 +89,7 @@ only. ==== [source,zsh] ---- -apt-get install g++ cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc dpkg +apt-get install g++ cmake libpoco-dev asciidoc dpkg ---- ==== diff --git a/cmake/packages.cmake b/cmake/packages.cmake index d845208..2f89eba 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -45,7 +45,7 @@ if (WITH_RPM) set(CPACK_RPM_PACKAGE_LICENSE "GPL-3") set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}") set(CPACK_RPM_PACKAGE_REQUIRES - "poco-netssl >= 1.6, poco-sqlite >= 1.6, libxdg-basedir") + "poco-netssl >= 1.6, poco-sqlite >= 1.6") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}") set(CPACK_SOURCE_PACKAGE_FILE_NAME diff --git a/cmake/remwhareadConfig.cmake.in b/cmake/remwhareadConfig.cmake.in index 5c1586e..1fb51f6 100644 --- a/cmake/remwhareadConfig.cmake.in +++ b/cmake/remwhareadConfig.cmake.in @@ -4,7 +4,5 @@ include(GNUInstallDirs) find_depencency(Poco COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML CONFIG REQUIRED) -find_dependency(PkgConfig REQUIRED) -pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/pkg-config/remwharead.pc.in b/pkg-config/remwharead.pc.in index 001d6b6..50b1518 100644 --- a/pkg-config/remwharead.pc.in +++ b/pkg-config/remwharead.pc.in @@ -9,5 +9,5 @@ Description: @PROJECT_DESCRIPTION@ Version: @PROJECT_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -l${name} -lPocoData -lstdc++fs -Requires.private: libxdg-basedir, icu-uc, icu-i18n +Requires.private: icu-uc, icu-i18n Libs.private: -lPocoFoundation -lPocoNet -lPocoNetSSL -lPocoDataSQLite -lPocoJSON -lPocoXML diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 3c1ed0f..09d46f1 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,7 +1,5 @@ include(GNUInstallDirs) -find_package(PkgConfig REQUIRED) -pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir) # Some distributions do not contain Poco*Config.cmake recipes. find_package(Poco COMPONENTS Foundation Net NetSSL Data DataSQLite JSON XML @@ -24,7 +22,7 @@ target_include_directories(${PROJECT_NAME} "$") target_link_libraries(${PROJECT_NAME} - PRIVATE PkgConfig::libxdg-basedir pthread + PRIVATE pthread PUBLIC stdc++fs) # If no Poco*Config.cmake recipes are found, look for headers in standard dirs. diff --git a/src/lib/sqlite.cpp b/src/lib/sqlite.cpp index f719b17..12de60f 100644 --- a/src/lib/sqlite.cpp +++ b/src/lib/sqlite.cpp @@ -18,8 +18,13 @@ #include "time.hpp" #include #include +#include +#if POCO_VERSION >= 0x01090000 // Path::dataHome() is only in 1.9 and above. +#include +#else +#include +#endif #include -#include #include #include @@ -29,16 +34,29 @@ using std::cerr; using std::endl; using namespace Poco::Data::Keywords; using Poco::Data::Statement; +#if POCO_VERSION < 0x01090000 +using Poco::Environment; +#endif Database::Database() : _connected(false) { try { - xdgHandle xdg; - xdgInitHandle(&xdg); - _dbpath = xdgDataHome(&xdg) / fs::path("remwharead"); - xdgWipeHandle(&xdg); + #if POCO_VERSION >= 0x01090000 + _dbpath = Poco::Path::dataHome() / fs::path("remwharead"); + #else + if (Environment::has("XDG_DATA_HOME")) + { + _dbpath = Environment::get("XDG_DATA_HOME") + / fs::path("remwharead"); + } + else if (Environment::has("HOME")) + { + _dbpath = Environment::get("HOME") + / fs::path(".local/share/remwharead"); + } // Else use current directory. + #endif if (!fs::exists(_dbpath)) { From 9937ecf5b0d903652e321ed7e622d52c176db0e8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 05:06:12 +0100 Subject: [PATCH 06/10] CI: Compile with g++-7 instead of 8. --- .drone.yml | 4 ++-- README.adoc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 4e237d4..7449b13 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,11 +13,11 @@ trigger: - tag steps: -- name: gcc8 +- name: gcc7 image: debian:buster-slim pull: always environment: - CXX: g++-8 + CXX: g++-7 CXXFLAGS: -pipe -O2 LANG: en_US.utf-8 commands: diff --git a/README.adoc b/README.adoc index 141cbe9..35693e9 100644 --- a/README.adoc +++ b/README.adoc @@ -76,7 +76,7 @@ only. ==== Dependencies * Tested OS: Linux -* C++ compiler (tested: {uri-gcc}[gcc] 8/9, {uri-clang}[clang] 6/7) +* C++ compiler (tested: {uri-gcc}[gcc] 7/8/9, {uri-clang}[clang] 6/7) * {uri-cmake}[cmake] (at least: 3.6) * {uri-poco}[POCO] (tested: 1.9 / 1.7) * Optional: From 253047c0b522f533340b0052f03e80bc8aa172cc Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 06:04:51 +0100 Subject: [PATCH 07/10] CI: Prepare rpm build. I couldn't find poco anywhere in the repos or EPEL. --- .drone.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.drone.yml b/.drone.yml index 7449b13..588375a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -153,6 +153,26 @@ steps: - name: debian-package-cache path: /var/cache/apt/archives +# - name: rpm +# image: centos:8 +# pull: always +# environment: +# CXX: g++ +# CXXFLAGS: -pipe -O2 +# commands: +# - sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf +# - yum install -qy epel-release +# - yum install --enablerepo=PowerTools --enablerepo=epel -qy gcc-c++ cmake poco-devel openssl-devel doxygen asciidoc rpm-build +# - rm -rf build && mkdir -p build && cd build +# - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_RPM=YES .. +# - make package +# - cmake -DWITH_RPM=YES -DWITH_DOC=NO .. +# - make package +# - cp -v remwharead-${DRONE_TAG}-0.x86_64.rpm .. +# volumes: +# - name: centos-package-cache +# path: /var/cache/yum + - name: release image: plugins/gitea-release pull: always From ff7b6338a08cea61cdcebfdeb3d20a7ac7ce5a09 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 07:21:18 +0100 Subject: [PATCH 08/10] Replace `Poco::Path::dataHome()` with `get_data_home()`. `Poco::Path::dataHome()` does not follow the XDG Base Directory Specification. --- include/sqlite.hpp | 2 ++ src/lib/sqlite.cpp | 38 +++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/sqlite.hpp b/include/sqlite.hpp index bb2b6d1..d341683 100644 --- a/include/sqlite.hpp +++ b/include/sqlite.hpp @@ -111,6 +111,8 @@ private: fs::path _dbpath; std::unique_ptr _session; bool _connected; + + fs::path get_data_home() const; }; } // namespace remwharead diff --git a/src/lib/sqlite.cpp b/src/lib/sqlite.cpp index 12de60f..65b68e4 100644 --- a/src/lib/sqlite.cpp +++ b/src/lib/sqlite.cpp @@ -19,11 +19,7 @@ #include #include #include -#if POCO_VERSION >= 0x01090000 // Path::dataHome() is only in 1.9 and above. -#include -#else #include -#endif #include #include #include @@ -34,30 +30,14 @@ using std::cerr; using std::endl; using namespace Poco::Data::Keywords; using Poco::Data::Statement; -#if POCO_VERSION < 0x01090000 using Poco::Environment; -#endif Database::Database() : _connected(false) { try { - #if POCO_VERSION >= 0x01090000 - _dbpath = Poco::Path::dataHome() / fs::path("remwharead"); - #else - if (Environment::has("XDG_DATA_HOME")) - { - _dbpath = Environment::get("XDG_DATA_HOME") - / fs::path("remwharead"); - } - else if (Environment::has("HOME")) - { - _dbpath = Environment::get("HOME") - / fs::path(".local/share/remwharead"); - } // Else use current directory. - #endif - + _dbpath = get_data_home(); if (!fs::exists(_dbpath)) { fs::create_directories(_dbpath); @@ -185,4 +165,20 @@ list Database::retrieve(const time_point &start, return {}; } + +fs::path Database::get_data_home() const +{ + fs::path path; + + if (Environment::has("XDG_DATA_HOME")) + { + path = Environment::get("XDG_DATA_HOME") / fs::path("remwharead"); + } + else if (Environment::has("HOME")) + { + path = Environment::get("HOME") / fs::path(".local/share/remwharead"); + } // Else return empty path. + + return path; +} } // namespace remwharead From 0a1396fc25fcff55707b9b7c6369fb30745b3957 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 20:38:58 +0100 Subject: [PATCH 09/10] Mark `URI::archive()` const. --- include/uri.hpp | 2 +- src/lib/uri.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uri.hpp b/include/uri.hpp index 90cb18b..54b2dce 100644 --- a/include/uri.hpp +++ b/include/uri.hpp @@ -101,7 +101,7 @@ public: * * @since 0.6.0 */ - archive_answer archive(); + archive_answer archive() const; protected: string _uri; diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp index a976718..26fc179 100644 --- a/src/lib/uri.cpp +++ b/src/lib/uri.cpp @@ -617,7 +617,7 @@ string URI::unescape_html(string html) return html; } -archive_answer URI::archive() +archive_answer URI::archive() const { if (_uri.substr(0, 4) != "http") { From b23347f61af4ef7782631492a65d2b2610cee7fc Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Oct 2019 20:43:32 +0100 Subject: [PATCH 10/10] Do the archiving parallel to the fetching. Potentially halves the time needed. --- src/cli/main.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/cli/main.cpp b/src/cli/main.cpp index e95600d..f7e142c 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace remwharead; using namespace remwharead_cli; @@ -76,6 +77,17 @@ int App::main(const std::vector &args) if (!_uri.empty()) { URI uri(_uri); + + archive_answer archive_data; + std::thread thread_archive; + if (_archive) + { + thread_archive = std::thread([&archive_data, &uri] + { + archive_data = uri.archive(); + }); + } + html_extract page = uri.get(); if (!page) { @@ -84,17 +96,17 @@ int App::main(const std::vector &args) return 3; } - archive_answer archive; if (_archive) { - archive = uri.archive(); - if (!archive) + thread_archive.join(); + if (!archive_data) { - cerr << "Error archiving URL: " << archive.error << endl; + cerr << "Error archiving URL: " << archive_data.error << endl; } } - db.store({_uri, archive.uri, system_clock::now(), _tags, page.title, - page.description, page.fulltext}); + + db.store({_uri, archive_data.uri, system_clock::now(), _tags, + page.title, page.description, page.fulltext}); } ofstream file;