SyncEngine: Add a compile option so we rename to restoring a move we don't have the...
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 12 May 2016 11:14:07 +0000 (13:14 +0200)
committerOlivier Goffart <ogoffart@woboq.com>
Thu, 12 May 2016 11:15:30 +0000 (13:15 +0200)
IL issue 550

CMakeLists.txt
src/libsync/syncengine.cpp

index 853be4eb0ac7f0644ffd139f8ad6940bf5caf195..35561596f8e2323c1809eb4fe96a4bd4cf40b5c7 100644 (file)
@@ -1,3 +1,4 @@
+
 cmake_minimum_required(VERSION 2.6)
 cmake_policy(VERSION 2.8.0)
 
@@ -122,6 +123,17 @@ if(OWNCLOUD_5XX_NO_BLACKLIST)
     add_definitions(-DOWNCLOUD_5XX_NO_BLACKLIST=1)
 endif()
 
+# When this option is enabled, a rename that is not allowed will be renamed back
+# do the original as a restoration step.  Withut this option, the restoration will
+# re-download the file instead.
+# The default is off because we don't want to rename the files back behind the user's back
+# Added for IL issue #550
+option(OWNCLOUD_RESTORE_RENAME "OWNCLOUD_RESTORE_RENAME" OFF)
+if(OWNCLOUD_RESTORE_RENAME)
+    add_definitions(-DOWNCLOUD_RESTORE_RENAME=1)
+endif()
+
+
 if(APPLE)
   set( SOCKETAPI_TEAM_IDENTIFIER_PREFIX "" CACHE STRING "SocketApi prefix (including a following dot) that must match the codesign key's TeamIdentifier/Organizational Unit" )
 endif()
index 8a19fdc69c22e2185d32faecf86c5df7d6f0f65a..aed09e5b1e62b7e14e1e37226cfe36166f8dced2 100644 (file)
@@ -1182,15 +1182,18 @@ void SyncEngine::checkForPermission()
                     }
                 }
 
-#if 0 /* We don't like the idea of renaming behind user's back, as the user may be working with the files */
-
-                if (!sourceOK && !destinationOK) {
+#ifdef OWNCLOUD_RESTORE_RENAME /* We don't like the idea of renaming behind user's back, as the user may be working with the files */
+                if (!sourceOK && (!destinationOK || isRename)
+                        // (not for directory because that's more complicated with the contents that needs to be adjusted)
+                        && !(*it)->_isDirectory) {
                     // Both the source and the destination won't allow move.  Move back to the original
                     std::swap((*it)->_file, (*it)->_renameTarget);
                     (*it)->_direction = SyncFileItem::Down;
                     (*it)->_errorString = tr("Move not allowed, item restored");
                     (*it)->_isRestoration = true;
                     qDebug() << "checkForPermission: MOVING BACK" << (*it)->_file;
+                    // in case something does wrong, we will not do it next time
+                    _journal->avoidRenamesOnNextSync((*it)->_file);
                 } else
 #endif
                 if (!sourceOK || !destinationOK) {