libsync: use the new webdav url if the server reports it
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 16 Nov 2016 08:30:29 +0000 (09:30 +0100)
committerOlivier Goffart <olivier@woboq.com>
Tue, 29 Nov 2016 15:16:20 +0000 (16:16 +0100)
The rules to select the webdav url are now:

 - If the server reports that the new chunking algorithm is working,
   always use remote.php/dav/files/<username>
   This capability can be overriden with an environment variable

 - Otherwise, use the dav path provided by the theme, which defaults to
   remote.php/webdav

This means that with the newer server, the branding can no longer override
the webdav URL. If there is still an usecase for the branding to do so, we
need to find another way to override it. But it is now more complicated to
configure as might need include the username and need different endpoint
depending on the operations (chunks or not)

Issue #4007

src/libsync/account.cpp
src/libsync/capabilities.cpp
src/libsync/owncloudpropagator.cpp
src/libsync/propagateuploadng.cpp

index 94d87c39c1b597de4a7deef6d41bd3be8cf3883a..1b96dabf837c8a091f570329f1a70346f5a1a9a6 100644 (file)
@@ -57,6 +57,11 @@ Account::~Account()
 
 QString Account::davPath() const
 {
+    if (capabilities().chunkingNg()) {
+        // The chunking-ng means the server prefer to use the new webdav URL
+        return QLatin1String("/remote.php/dav/files/") + davUser() + QLatin1Char('/');
+    }
+
     // make sure to have a trailing slash
     if( !_davPath.endsWith('/') ) {
         QString dp(_davPath);
index 14acfa3a6b6812a7d0f65333d6392b2b11a795bc..31cd76b4c2c09963c548e0a65deb9c10a0fd383c 100644 (file)
@@ -110,6 +110,9 @@ QByteArray Capabilities::uploadChecksumType() const
 
 bool Capabilities::chunkingNg() const
 {
+    static const auto chunkng = qgetenv("OWNCLOUD_CHUNKING_NG");
+    if (chunkng == "0") return false;
+    if (chunkng == "1") return true;
     return _capabilities["dav"].toMap()["chunking"].toByteArray() >= "1.0";
 }
 
index f31aa167605cb42a8791e88f9683d44967fc4777..38011862d6f0ec662d1fbbb4e99acb762495aae5 100644 (file)
@@ -271,9 +271,7 @@ PropagateItemJob* OwncloudPropagator::createJob(const SyncFileItemPtr &item) {
                 return job;
             } else {
                 PropagateUploadFileCommon *job = 0;
-                static const auto chunkng = qgetenv("OWNCLOUD_CHUNKING_NG");
-                if (item->_size > chunkSize()
-                        && (account()->capabilities().chunkingNg() || chunkng == "1") && chunkng != "0") {
+                if (item->_size > chunkSize() && account()->capabilities().chunkingNg()) {
                     job = new PropagateUploadFileNG(this, item);
                 } else {
                     job = new PropagateUploadFileV1(this, item);
index 7b10288ede11db86c1ab134124c7255911e3da6e..106b0dcdb2fc86b1362f8ecfbc8a9c90c9a7bf38 100644 (file)
@@ -268,10 +268,8 @@ void PropagateUploadFileNG::startNextChunk()
         Q_ASSERT(_jobs.isEmpty()); // There should be no running job anymore
         _finished = true;
         // Finish with a MOVE
-        QString destination = _propagator->account()->url().path()
-            + QLatin1String("/remote.php/dav/files/") + _propagator->account()->davUser()
-            + _propagator->_remoteFolder + _item->_file;
-
+        QString destination = QDir::cleanPath(_propagator->account()->url().path() + QLatin1Char('/')
+            + _propagator->account()->davPath() + _propagator->_remoteFolder + _item->_file);
         auto headers = PropagateUploadFileCommon::headers();
 
         // "If-Match applies to the source, but we are interested in comparing the etag of the destination