8000 Fix compilation with DOWNLOAD_ENABLED=OFF by ahojnnes · Pull Request #3053 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix compilation with DOWNLOAD_ENABLED=OFF #3053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/colmap/util/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,13 @@ std::string ComputeSHA256(const std::string_view& str) {
return digest.str();
}

#endif // COLMAP_DOWNLOAD_ENABLED

namespace {

std::optional<std::filesystem::path> 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<std::string> parts = StringSplit(uri, ";");
THROW_CHECK_EQ(parts.size(), 3)
<< "Invalid URI format. Expected: <url>;<name>;<sha256>";
Expand Down Expand Up @@ -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
11 changes: 6 additions & 5 deletions src/colmap/util/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,23 @@ std::optional<std::string> 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
// "<url>;<name>;<sha256>". The file will be cached under
// $HOME/.cache/colmap/<sha256>-<name>. File integrity is checked against the
// provided SHA256 digest. Throws exception if the digest does not match.
// 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 "<url>;<name>;<sha256>" 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
////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading
0