From 0aa2603a23b96c3b819ac7d803bdcc43c0349587 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 Sep 2021 14:44:48 +0200 Subject: [PATCH] [libcalamares] Fix network-connectivity check on old Qt With old Qt, Calamares could only run one check on a thread, because the NAM would be switched to NotAccessible -- subsequent checks would fail because the NAM is already hard-set to NotAccessible, so it could never be turned back on by Calamares code. Reset the accessible flag for the NAM while checking if the internet is there. --- src/libcalamares/network/Manager.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/network/Manager.cpp b/src/libcalamares/network/Manager.cpp index cceff477e..6cb270ecd 100644 --- a/src/libcalamares/network/Manager.cpp +++ b/src/libcalamares/network/Manager.cpp @@ -162,6 +162,15 @@ Manager::checkHasInternet() { return false; } + // It's possible that access was switched off (see below, if the check + // fails) so we want to turn it back on first. Otherwise all the + // checks will fail **anyway**, defeating the point of the checks. +#if ( QT_VERSION < QT_VERSION_CHECK( 5, 15, 0 ) ) + if ( !d->m_hasInternet ) + { + d->nam()->setNetworkAccessible( QNetworkAccessManager::Accessible ); + } +#endif if ( d->m_lastCheckedUrlIndex < 0 ) { d->m_lastCheckedUrlIndex = 0; @@ -189,8 +198,7 @@ Manager::checkHasInternet() // For earlier Qt versions (< 5.15.0), set the accessibility flag to // NotAccessible if synchronous ping has failed, so that any module // using Qt's networkAccessible method to determine whether or not -// internet connection is actually avaialable won't get confused over -// virtualization technologies. +// internet connection is actually available won't get confused. #if ( QT_VERSION < QT_VERSION_CHECK( 5, 15, 0 ) ) if ( !d->m_hasInternet ) { @@ -261,6 +269,7 @@ asynchronousRun( QNetworkAccessManager* nam, const QUrl& url, const RequestOptio // Bail out early if the request is bad if ( reply->error() ) { + cWarning() << "Early reply error" << reply->error() << reply->errorString(); reply->deleteLater(); return nullptr; }