Packages: consider checksum failures for retry.
This means an out-of-sync mirror causes a retry on a different mirror server.
This commit is contained in:
committed by
Automatic Release Builder
parent
fcd8ebb8a3
commit
29f6d06f1a
@@ -635,7 +635,7 @@ void ArchiveExtractor::extractBytes(const uint8_t* bytes, size_t count)
|
|||||||
d.reset(new ZipExtractorPrivate(this));
|
d.reset(new ZipExtractorPrivate(this));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SG_LOG(SG_IO, SG_ALERT, "Invcalid archive type");
|
SG_LOG(SG_IO, SG_WARN, "Invalid archive type");
|
||||||
_invalidDataType = true;
|
_invalidDataType = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
m_extractPath = aOwner->path().dir();
|
m_extractPath = aOwner->path().dir();
|
||||||
m_extractPath.append("_extract_" + aOwner->package()->md5());
|
m_extractPath.append("_extract_" + aOwner->package()->md5());
|
||||||
|
|
||||||
// clean up any existing files
|
// clean up any existing files (eg from previous failed download)
|
||||||
Dir d(m_extractPath);
|
Dir d(m_extractPath);
|
||||||
if (d.exists()) {
|
if (d.exists()) {
|
||||||
d.remove(true /* recursive */);
|
d.remove(true /* recursive */);
|
||||||
@@ -106,7 +106,9 @@ protected:
|
|||||||
Request::responseHeadersComplete();
|
Request::responseHeadersComplete();
|
||||||
|
|
||||||
Dir d(m_extractPath);
|
Dir d(m_extractPath);
|
||||||
d.create(0755);
|
if (!d.create(0755)) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "Failed to create extraction directory" << d.path());
|
||||||
|
}
|
||||||
|
|
||||||
m_extractor.reset(new ArchiveExtractor(m_extractPath));
|
m_extractor.reset(new ArchiveExtractor(m_extractPath));
|
||||||
memset(&m_md5, 0, sizeof(SG_MD5_CTX));
|
memset(&m_md5, 0, sizeof(SG_MD5_CTX));
|
||||||
@@ -115,11 +117,20 @@ protected:
|
|||||||
|
|
||||||
void gotBodyData(const char* s, int n) override
|
void gotBodyData(const char* s, int n) override
|
||||||
{
|
{
|
||||||
|
// if there's a pre-existing error, discard byte sinstead of pushing
|
||||||
|
// more through the extactor
|
||||||
|
if (m_extractor->hasError()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const uint8_t* ubytes = (uint8_t*) s;
|
const uint8_t* ubytes = (uint8_t*) s;
|
||||||
SG_MD5Update(&m_md5, ubytes, n);
|
SG_MD5Update(&m_md5, ubytes, n);
|
||||||
m_downloaded += n;
|
m_downloaded += n;
|
||||||
m_owner->installProgress(m_downloaded, responseLength());
|
m_owner->installProgress(m_downloaded, responseLength());
|
||||||
m_extractor->extractBytes(ubytes, n);
|
m_extractor->extractBytes(ubytes, n);
|
||||||
|
if (m_extractor->hasError()) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_WARN, "archive extraction failed (from " + m_activeURL + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDone() override
|
void onDone() override
|
||||||
@@ -214,7 +225,9 @@ private:
|
|||||||
dir.remove(true /* recursive */);
|
dir.remove(true /* recursive */);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto canRetry = (aReason == Delegate::FAIL_NOT_FOUND) || (aReason == Delegate::FAIL_DOWNLOAD);
|
const auto canRetry = (aReason == Delegate::FAIL_NOT_FOUND) ||
|
||||||
|
(aReason == Delegate::FAIL_DOWNLOAD) || (aReason == Delegate::FAIL_CHECKSUM);
|
||||||
|
|
||||||
if (canRetry && !m_urls.empty()) {
|
if (canRetry && !m_urls.empty()) {
|
||||||
SG_LOG(SG_GENERAL, SG_WARN, "archive download failed from:" << m_activeURL
|
SG_LOG(SG_GENERAL, SG_WARN, "archive download failed from:" << m_activeURL
|
||||||
<< "\n\twill retry with next mirror");
|
<< "\n\twill retry with next mirror");
|
||||||
@@ -226,7 +239,6 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - try other mirrors
|
|
||||||
m_owner->m_download.reset(); // ensure we get cleaned up
|
m_owner->m_download.reset(); // ensure we get cleaned up
|
||||||
m_owner->installResult(aReason);
|
m_owner->installResult(aReason);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,14 +122,17 @@ void printPackageInfo(pkg::Package* pkg)
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
sglog().setLogLevels( SG_ALL, SG_INFO );
|
||||||
|
|
||||||
HTTP::Client* http = new HTTP::Client();
|
HTTP::Client* http = new HTTP::Client();
|
||||||
pkg::Root* root = new pkg::Root(Dir::current().path(), "");
|
|
||||||
|
SGPath rootPath = SGPath::fromEnv("SG_PKG_ROOT", Dir::current().path());
|
||||||
|
pkg::Root* root = new pkg::Root(rootPath, "2019.1.1");
|
||||||
|
|
||||||
MyDelegate dlg;
|
MyDelegate dlg;
|
||||||
root->addDelegate(&dlg);
|
root->addDelegate(&dlg);
|
||||||
|
|
||||||
cout << "Package root is:" << Dir::current().path() << endl;
|
cout << "Package root is:" << rootPath << endl;
|
||||||
cout << "have " << root->catalogs().size() << " catalog(s)" << endl;
|
cout << "have " << root->catalogs().size() << " catalog(s)" << endl;
|
||||||
|
|
||||||
root->setHTTPClient(http);
|
root->setHTTPClient(http);
|
||||||
|
|||||||
Reference in New Issue
Block a user