Follow redirection when downloading db
This commit is contained in:
parent
ec3123b5de
commit
3c47354e06
|
@ -204,12 +204,16 @@ PackageDetailAvailability AlpmDatabase::requestsRequired(PackageDetail packageDe
|
|||
|
||||
QNetworkRequest AlpmDatabase::regularDatabaseRequest()
|
||||
{
|
||||
return QNetworkRequest(QUrl(serverUrls().front() % QChar('/') % name() % QStringLiteral(".db")));
|
||||
return QNetworkRequest(m_filesRedirs.isEmpty()
|
||||
? (QUrl(serverUrls().front() % QChar('/') % name() % QStringLiteral(".db")))
|
||||
: m_regularRedirs.back());
|
||||
}
|
||||
|
||||
QNetworkRequest AlpmDatabase::filesDatabaseRequest()
|
||||
{
|
||||
return QNetworkRequest(QUrl(serverUrls().front() % QChar('/') % name() % QStringLiteral(".files")));
|
||||
return QNetworkRequest(m_filesRedirs.isEmpty()
|
||||
? (QUrl(serverUrls().front() % QChar('/') % name() % QStringLiteral(".files")))
|
||||
: m_filesRedirs.back());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -266,8 +270,25 @@ void AlpmDatabase::databaseDownloadFinished()
|
|||
auto *reply = static_cast<QNetworkReply *>(sender());
|
||||
reply->deleteLater();
|
||||
bool filesDatabase = reply->property("filesDatabase").toBool();
|
||||
const QString redirTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
|
||||
QReadLocker locker(lock());
|
||||
if(reply->error() == QNetworkReply::NoError) {
|
||||
switch(reply->error()) {
|
||||
case QNetworkReply::NoError: {
|
||||
if(!redirTarget.isEmpty()) {
|
||||
if((!filesDatabase && m_regularRedirs.contains(redirTarget)) || (filesDatabase && m_filesRedirs.contains(redirTarget))) {
|
||||
cerr << "Redirection-loop for database file [" << name().toLocal8Bit().data() << "]" << endl;
|
||||
removeBusyFlag();
|
||||
return;
|
||||
}
|
||||
|
||||
(filesDatabase ? m_filesRedirs : m_regularRedirs) << redirTarget;
|
||||
cerr << "Redirection target for database file [" << name().toLocal8Bit().data() << "] available: " << redirTarget.toLocal8Bit().data() << endl;
|
||||
|
||||
locker.unlock();
|
||||
downloadDatabase(m_downloadTargetDir, filesDatabase);
|
||||
}
|
||||
m_filesRedirs.clear();
|
||||
|
||||
QString newDatabasePath;
|
||||
cerr << "Downloaded database file for [" << name().toLocal8Bit().data() << "] successfully." << endl;
|
||||
newDatabasePath = m_downloadTargetDir % QChar('/') % name() % (filesDatabase ? QStringLiteral(".files") : QStringLiteral(".db"));
|
||||
|
@ -295,7 +316,7 @@ void AlpmDatabase::databaseDownloadFinished()
|
|||
cerr << "An IO error occured when storing database file for [" << name().toLocal8Bit().data() << "]: Unable to create/write output file." << endl;
|
||||
removeBusyFlag();
|
||||
}
|
||||
} else {
|
||||
} default:
|
||||
cerr << "An error occured when dwonloading database file for [" << name().toLocal8Bit().data() << "]: " << reply->errorString().toLocal8Bit().data() << endl;
|
||||
if(filesDatabase && reply->error() == QNetworkReply::ContentNotFoundError) {
|
||||
cerr << "-> Attempting to download regular database file instead of files database file." << endl;
|
||||
|
@ -304,6 +325,7 @@ void AlpmDatabase::databaseDownloadFinished()
|
|||
} else {
|
||||
removeBusyFlag();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,8 @@ private:
|
|||
|
||||
QString m_dbPath;
|
||||
QString m_downloadTargetDir;
|
||||
QStringList m_regularRedirs;
|
||||
QStringList m_filesRedirs;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue