Merge pull request #453 from owncloud/improve_action_bar_pr_392_with_develop
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / RenameFileOperation.java
index 1eecfc2..a007af2 100644 (file)
@@ -20,14 +20,13 @@ package com.owncloud.android.operations;
 import java.io.File;
 import java.io.IOException;
 
 import java.io.File;
 import java.io.IOException;
 
-import org.apache.commons.httpclient.HttpException;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
-import com.owncloud.android.oc_framework.operations.RemoteOperation;
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
 
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
 
@@ -78,7 +77,7 @@ public class RenameFileOperation extends RemoteOperation {
      * @param   client      Client object to communicate with the remote ownCloud server.
      */
     @Override
      * @param   client      Client object to communicate with the remote ownCloud server.
      */
     @Override
-    protected RemoteOperationResult run(WebdavClient client) {
+    protected RemoteOperationResult run(OwnCloudClient client) {
         RemoteOperationResult result = null;
         
         // check if the new name is valid in the local file system
         RemoteOperationResult result = null;
         
         // check if the new name is valid in the local file system
@@ -93,32 +92,27 @@ public class RenameFileOperation extends RemoteOperation {
                 mNewRemotePath += OCFile.PATH_SEPARATOR;
             }
 
                 mNewRemotePath += OCFile.PATH_SEPARATOR;
             }
 
-            // check if a file with the new name already exists
-            if (client.existsFile(mNewRemotePath) ||                             // remote check could fail by network failure. by indeterminate behavior of HEAD for folders ... 
-                    mStorageManager.getFileByPath(mNewRemotePath) != null) {     // ... so local check is convenient
+            // ckeck local overwrite
+            if (mStorageManager.getFileByPath(mNewRemotePath) != null) {
                 return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
             }
                 return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
             }
-        
-        RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath(), mNewName
-                mNewRemotePath, mFile.isFolder());
-        result = operation.execute(client);
+            
+            RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath()
+                    mNewName, mFile.isFolder());
+            result = operation.execute(client);
 
 
-        if (result.isSuccess()) {
-            if (mFile.isFolder()) {
-                saveLocalDirectory();
+            if (result.isSuccess()) {
+                if (mFile.isFolder()) {
+                    saveLocalDirectory();
 
 
-            } else {
-                saveLocalFile();
+                } else {
+                    saveLocalFile();
+                }
             }
             }
-        }
-        } catch (HttpException e) {
-            Log_OC.e(TAG, "Rename " + mFile.getRemotePath() + " to " + ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + 
-                    ((result!= null) ? result.getLogMessage() : ""), e);
-            e.printStackTrace();
+            
         } catch (IOException e) {
             Log_OC.e(TAG, "Rename " + mFile.getRemotePath() + " to " + ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + 
                     ((result!= null) ? result.getLogMessage() : ""), e);
         } catch (IOException e) {
             Log_OC.e(TAG, "Rename " + mFile.getRemotePath() + " to " + ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + 
                     ((result!= null) ? result.getLogMessage() : ""), e);
-            e.printStackTrace();
         }
 
         return result;
         }
 
         return result;