From 3d3a38767ac4806348aa85bd30dd96644ff6f9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 17 Dec 2024 17:49:57 +0100 Subject: [PATCH] Fix compilation with DOWNLOAD_ENABLED=OFF --- src/colmap/util/file.cc | 21 ++++++++++----------- src/colmap/util/file.h | 11 ++++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/colmap/util/file.cc b/src/colmap/util/file.cc index 2bf5dde2b5..2ac2950993 100644 --- a/src/colmap/util/file.cc +++ b/src/colmap/util/file.cc @@ -369,8 +369,6 @@ std::string ComputeSHA256(const std::string_view& str) { return digest.str(); } -#endif // COLMAP_DOWNLOAD_ENABLED - namespace { std::optional download_cache_dir_overwrite; @@ -378,10 +376,6 @@ std::optional download_cache_dir_overwrite; } std::string DownloadAndCacheFile(const std::string& uri) { -#ifndef COLMAP_DOWNLOAD_ENABLED - throw std::invalid_argument("COLMAP was compiled without download support"); -#endif - const std::vector parts = StringSplit(uri, ";"); THROW_CHECK_EQ(parts.size(), 3) << "Invalid URI format. Expected: ;;"; @@ -423,17 +417,22 @@ std::string DownloadAndCacheFile(const std::string& uri) { return path.string(); } +void OverwriteDownloadCacheDir(std::filesystem::path path) { + download_cache_dir_overwrite = std::move(path); +} + +#endif // COLMAP_DOWNLOAD_ENABLED + std::string MaybeDownloadAndCacheFile(const std::string& uri) { if (!StringStartsWith(uri, "http://") && !StringStartsWith(uri, "https://") && !StringStartsWith(uri, "file://")) { return uri; } - +#ifdef COLMAP_DOWNLOAD_ENABLED return DownloadAndCacheFile(uri); -} - -void OverwriteDownloadCacheDir(std::filesystem::path path) { - download_cache_dir_overwrite = std::move(path); +#else + throw std::runtime_error("COLMAP was compiled without download support"); +#endif } } // namespace colmap diff --git a/src/colmap/util/file.h b/src/colmap/util/file.h index e850074fc2..a6ae073246 100644 --- a/src/colmap/util/file.h +++ b/src/colmap/util/file.h @@ -142,8 +142,6 @@ std::optional DownloadFile(const std::string& url); // Computes SHA256 digest for given string. std::string ComputeSHA256(const std::string_view& str); -#endif // COLMAP_DOWNLOAD_ENABLED - // Downloads and caches file from given URI. The URI must take the format // ";;". The file will be cached under // $HOME/.cache/colmap/-. File integrity is checked against the @@ -151,13 +149,16 @@ std::string ComputeSHA256(const std::string_view& str); // Returns the path to the cached file. std::string DownloadAndCacheFile(const std::string& uri); +// Overwrites the default download cache directory at $HOME/.cache/colmap/. +void OverwriteDownloadCacheDir(std::filesystem::path path); + +#endif // COLMAP_DOWNLOAD_ENABLED + // If the given URI is a local filesystem path, returns the input path. If the // URI matches the ";;" format, calls DownloadAndCacheFile(). +// Throws runtime exception if download is not supported. std::string MaybeDownloadAndCacheFile(const std::string& uri); -// Overwrites the default download cache directory at $HOME/.cache/colmap/. -void OverwriteDownloadCacheDir(std::filesystem::path path); - //////////////////////////////////////////////////////////////////////////////// // Implementation ////////////////////////////////////////////////////////////////////////////////