Skip to content

Commit 45be73c

Browse files
committed
CcdbApi improvements
* fix memory bug occurring on MacOS BigSur + Ubuntu * optimization of location search loop * use new better alien-token-info (no timeout needed anymore)
1 parent d1b2b90 commit 45be73c

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

CCDB/src/CcdbApi.cxx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ bool CcdbApi::checkAlienToken() const
659659
if (getenv("JALIEN_TOKEN_CERT")) {
660660
return true;
661661
}
662-
auto returncode = system("timeout 1s timeout 1s alien-token-info &> /dev/null");
662+
auto returncode = system("alien-token-info > /dev/null 2> /dev/null");
663663
return returncode == 0;
664664
}
665665

@@ -757,20 +757,30 @@ void* CcdbApi::navigateURLsAndRetrieveContent(CURL* curl_handle, std::string con
757757
else if (300 <= response_code && response_code < 400) {
758758
// we try content locations in order of appearance until one succeeds
759759
// 1st: The "Location" field
760-
// 2nd: Possible "Content-Location" fields
761-
auto tryLocations = [this, &curl_handle, &content, cl](auto range) {
760+
// 2nd: Possible "Content-Location" fields - Location field
761+
std::vector<std::string> locs;
762+
auto iter = mHeaderData.find("Location");
763+
if (iter != mHeaderData.end()) {
764+
locs.push_back(iter->second);
765+
}
766+
// add alternative locations (not yet included)
767+
auto iter2 = mHeaderData.find("Content-Location");
768+
if (iter2 != mHeaderData.end()) {
769+
auto range = mHeaderData.equal_range("Content-Location");
762770
for (auto it = range.first; it != range.second; ++it) {
763-
auto nextlocation = it->second;
764-
LOG(DEBUG) << "Trying content location " << nextlocation;
765-
content = navigateURLsAndRetrieveContent(curl_handle, nextlocation, cl, nullptr);
771+
if (std::find(locs.begin(), locs.end(), it->second) == locs.end()) {
772+
locs.push_back(it->second);
773+
}
774+
}
775+
}
776+
for (auto& l : locs) {
777+
if (l.size() > 0) {
778+
LOG(DEBUG) << "Trying content location " << l;
779+
content = navigateURLsAndRetrieveContent(curl_handle, l, cl, nullptr);
766780
if (content /* or other success marker in future */) {
767781
break;
768782
}
769783
}
770-
};
771-
tryLocations(mHeaderData.equal_range("Location"));
772-
if (content == nullptr) {
773-
tryLocations(mHeaderData.equal_range("Content-Location"));
774784
}
775785
} else if (response_code == 404) {
776786
LOG(ERROR) << "Requested resource does not exist";

0 commit comments

Comments
 (0)