diff data/fileio/FileSource.cpp @ 913:b9d7352336ce

Fixes to FileSource from Ted Felix (for Rosegarden): avoid blowing up through calling abort() from cleanup() when error occurred; set status correctly for FTP transfers
author Chris Cannam
date Mon, 19 May 2014 10:54:45 +0100
parents 55e552b4f1b7
children 613ee830de5e
line wrap: on
line diff
--- a/data/fileio/FileSource.cpp	Wed May 14 09:54:20 2014 +0100
+++ b/data/fileio/FileSource.cpp	Mon May 19 10:54:45 2014 +0100
@@ -485,7 +485,10 @@
     if (m_reply) {
         QNetworkReply *r = m_reply;
         m_reply = 0;
-        r->abort();
+        // Can only call abort() when there are no errors.
+        if (r->error() == QNetworkReply::NoError) {
+            r->abort();
+        }
         r->deleteLater();
     }
     if (m_localFile) {
@@ -518,11 +521,14 @@
 {
     waitForStatus();
     bool available = true;
-    if (!m_ok) available = false;
-    else available = (m_lastStatus / 100 == 2);
+    if (!m_ok) {
+        available = false;
+    } else {
+        // http 2xx status codes mean success
+        available = (m_lastStatus / 100 == 2);
+    }
 #ifdef DEBUG_FILE_SOURCE
-    cerr << "FileSource::isAvailable: " << (available ? "yes" : "no")
-              << endl;
+    cerr << "FileSource::isAvailable: " << (available ? "yes" : "no") << endl;
 #endif
     return available;
 }
@@ -634,9 +640,12 @@
         return;
     }
 
+    // Handle http transfer status codes.
+
     int status =
         m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 
+    // If this is a redirection (3xx) code, do the redirect
     if (status / 100 == 3) {
         QString location = m_reply->header
             (QNetworkRequest::LocationHeader).toString();
@@ -665,6 +674,8 @@
     }
 
     m_lastStatus = status;
+
+    // 400 and up are failures, get the error string
     if (m_lastStatus / 100 >= 4) {
         m_errorString = QString("%1 %2")
             .arg(status)
@@ -713,6 +724,13 @@
 
     if (m_done) return;
 
+    QString scheme = m_url.scheme().toLower();
+    // For ftp transfers, replyFinished() will be called on success.
+    // metaDataChanged() is never called for ftp transfers.
+    if (scheme == "ftp") {
+        m_lastStatus = 200;  // http ok
+    }
+
     bool error = (m_lastStatus / 100 >= 4);
 
     cleanup();