[Pkg-owncloud-commits] [owncloud-client] 57/164: Handle 503 due to maintenance more gracefully. #2884

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:56:52 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 5c7fd24ea8ad1d92fbe2810fcbdbf9f2ecd14506
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Wed Feb 25 09:49:39 2015 +0100

    Handle 503 due to maintenance more gracefully. #2884
---
 src/gui/accountsettings.cpp         | 14 +++++---------
 src/gui/accountstate.cpp            | 10 ++++++++++
 src/gui/accountstate.h              |  5 +++++
 src/gui/application.cpp             |  1 +
 src/gui/owncloudgui.cpp             |  2 +-
 src/libsync/connectionvalidator.cpp | 14 ++++++++++++++
 src/libsync/connectionvalidator.h   |  1 +
 7 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index 5a41c2a..f46cf80 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -156,7 +156,7 @@ void AccountSettings::slotFolderActivated( const QModelIndex& indx )
   } else {
       ui->_buttonAdd->setVisible(true);
   }
-  bool isConnected = _accountState && _accountState->state() == AccountState::Connected;
+  bool isConnected = _accountState && _accountState->isConnected();
   ui->_buttonAdd->setEnabled(isConnected);
   ui->_buttonEnable->setEnabled( isValid );
   ui->_buttonSelectiveSync->setEnabled(isConnected && isValid);
@@ -168,7 +168,7 @@ void AccountSettings::slotFolderActivated( const QModelIndex& indx )
     } else {
       ui->_buttonEnable->setText( tr( "Resume" ) );
     }
-    ui->_buttonEnable->setEnabled( _accountState && _accountState->state() == AccountState::Connected);
+    ui->_buttonEnable->setEnabled(isConnected);
   }
 }
 
@@ -234,11 +234,7 @@ void AccountSettings::slotAddFolder( Folder *folder )
     if( ! folder || folder->alias().isEmpty() ) return;
 
     QStandardItem *item = new QStandardItem();
-    bool isConnected = false;
-    if (_accountState) {
-        isConnected = (_accountState->state() == AccountState::Connected);
-    }
-    folderToModelItem( item, folder,  isConnected);
+    folderToModelItem( item, folder, _accountState && _accountState->isConnectedOrMaintenance());
     _model->appendRow( item );
     // in order to update the enabled state of the "Sync now" button
     connect(folder, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
@@ -541,7 +537,7 @@ void AccountSettings::slotUpdateFolderState( Folder *folder )
     }
 
     if( item ) {
-        folderToModelItem( item, folder, _accountState->state() == AccountState::Connected );
+        folderToModelItem( item, folder, _accountState->isConnectedOrMaintenance() );
     } else {
         // the dialog is not visible.
     }
@@ -798,7 +794,7 @@ void AccountSettings::slotAccountStateChanged(int state)
         foreach (Folder *folder, folderMan->map().values()) {
             slotUpdateFolderState(folder);
         }
-        if (state == AccountState::Connected) {
+        if (state == AccountState::Connected || state == AccountState::ServerMaintenance) {
             QString user;
             if (AbstractCredentials *cred = account->credentials()) {
                user = cred->user();
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index f4f217c..600650f 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -125,6 +125,8 @@ QString AccountState::stateString(State state)
         return QLatin1String("Disconnected");
     case Connected:
         return QLatin1String("Connected");
+    case ServerMaintenance:
+        return QLatin1String("ServerMaintenance");
     case NetworkError:
         return QLatin1String("NetworkError");
     case ConfigurationError:
@@ -152,6 +154,11 @@ bool AccountState::isConnected() const
     return _state == Connected;
 }
 
+bool AccountState::isConnectedOrMaintenance() const
+{
+    return isConnected() || _state == ServerMaintenance;
+}
+
 QuotaInfo *AccountState::quotaInfo()
 {
     return _quotaInfo;
@@ -214,6 +221,9 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta
     case ConnectionValidator::UserCanceledCredentials:
         setState(SignedOut);
         break;
+    case ConnectionValidator::ServerMaintenance:
+        setState(ServerMaintenance);
+        break;
     case ConnectionValidator::Timeout:
         setState(NetworkError);
         break;
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index 5905d15..8da575b 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -67,6 +67,10 @@ public:
         /// The account is successfully talking to the server.
         Connected,
 
+        /// The account is talking to the server, but the server is in
+        /// maintenance mode.
+        ServerMaintenance,
+
         /// Could not communicate with the server for some reason.
         /// We assume this may resolve itself over time and will try
         /// again automatically.
@@ -96,6 +100,7 @@ public:
     void setSignedOut(bool signedOut);
 
     bool isConnected() const;
+    bool isConnectedOrMaintenance() const;
 
     QuotaInfo *quotaInfo();
 
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index beab9dc..01d97ca 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -260,6 +260,7 @@ void Application::slotAccountStateChanged(int state)
         folderMan->setSyncEnabled(true);
         folderMan->slotScheduleAllFolders();
         break;
+    case AccountState::ServerMaintenance:
     case AccountState::SignedOut:
     case AccountState::ConfigurationError:
     case AccountState::NetworkError:
diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp
index c056781..bf777f8 100644
--- a/src/gui/owncloudgui.cpp
+++ b/src/gui/owncloudgui.cpp
@@ -221,7 +221,7 @@ void ownCloudGui::slotComputeOverallSyncStatus()
             _tray->setToolTip(tr("Please sign in"));
             return;
         }
-        if (!a->isConnected()) {
+        if (!a->isConnectedOrMaintenance()) {
             _tray->setIcon(Theme::instance()->folderOfflineIcon(true));
             _tray->setToolTip(tr("Disconnected from server"));
             return;
diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp
index e8dace6..8cc5345 100644
--- a/src/libsync/connectionvalidator.cpp
+++ b/src/libsync/connectionvalidator.cpp
@@ -46,6 +46,8 @@ QString ConnectionValidator::statusString( Status stat )
         return QLatin1String("Status not found");
     case UserCanceledCredentials:
         return QLatin1String("User canceled credentials");
+    case ServerMaintenance:
+        return QLatin1String("Server in maintenance mode");
     case Timeout:
         return QLatin1String("Timeout");
     }
@@ -146,6 +148,18 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply)
 
     } else if( reply->error() != QNetworkReply::NoError ) {
         _errors << reply->errorString();
+
+        const int httpStatus =
+                reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+        if ( httpStatus == 503 ) {
+            // Is this a maintenance mode reply from the server
+            // or a regular 503 from somewhere else?
+            QByteArray body = reply->readAll();
+            if ( body.contains("Sabre\\DAV\\Exception\\ServiceUnavailable") ) {
+                _errors.clear();
+                stat = ServerMaintenance;
+            }
+        }
     }
 
     reportResult( stat );
diff --git a/src/libsync/connectionvalidator.h b/src/libsync/connectionvalidator.h
index 9f6bc93..f804d7f 100644
--- a/src/libsync/connectionvalidator.h
+++ b/src/libsync/connectionvalidator.h
@@ -75,6 +75,7 @@ public:
         CredentialsWrong,
         StatusNotFound,
         UserCanceledCredentials,
+        ServerMaintenance,
         // actually also used for other errors on the authed request
         Timeout
     };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list