Files uploaded in the past are copied to the local ownCloud directory during account...
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / RemoveFileOperation.java
index aa57356..bfc063f 100644 (file)
@@ -18,6 +18,7 @@
 
 package com.owncloud.android.operations;
 
 
 package com.owncloud.android.operations;
 
+import org.apache.commons.httpclient.HttpStatus;
 import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
 
 import android.util.Log;
 import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
 
 import android.util.Log;
@@ -35,7 +36,7 @@ import eu.alefzero.webdav.WebdavUtils;
  */
 public class RemoveFileOperation extends RemoteOperation {
     
  */
 public class RemoveFileOperation extends RemoteOperation {
     
-    private static final String TAG = RemoveFileOperation.class.getCanonicalName();
+    private static final String TAG = RemoveFileOperation.class.getSimpleName();
 
     private static final int REMOVE_READ_TIMEOUT = 10000;
     private static final int REMOVE_CONNECTION_TIMEOUT = 5000;
 
     private static final int REMOVE_READ_TIMEOUT = 10000;
     private static final int REMOVE_CONNECTION_TIMEOUT = 5000;
@@ -60,7 +61,19 @@ public class RemoveFileOperation extends RemoteOperation {
     
     
     /**
     
     
     /**
-     * Performs the removal
+     * Getter for the file to remove (or removed, if the operation was successfully performed).
+     * 
+     * @return      File to remove or already removed.
+     */
+    public OCFile getFile() {
+        return mFileToRemove;
+    }
+    
+    
+    /**
+     * Performs the remove operation
+     * 
+     * @param   client      Client object to communicate with the remote ownCloud server.
      */
     @Override
     protected RemoteOperationResult run(WebdavClient client) {
      */
     @Override
     protected RemoteOperationResult run(WebdavClient client) {
@@ -69,11 +82,15 @@ public class RemoveFileOperation extends RemoteOperation {
         try {
             delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));
             int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
         try {
             delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));
             int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
-            if (delete.succeeded()) {
-                mDataStorageManager.removeFile(mFileToRemove, mDeleteLocalCopy);
+            if (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND) {
+                if (mFileToRemove.isDirectory()) {
+                    mDataStorageManager.removeDirectory(mFileToRemove, true, mDeleteLocalCopy);
+                } else {
+                    mDataStorageManager.removeFile(mFileToRemove, mDeleteLocalCopy);
+                }
             }
             delete.getResponseBodyAsString();   // exhaust the response, although not interesting
             }
             delete.getResponseBodyAsString();   // exhaust the response, although not interesting
-            result = new RemoteOperationResult(delete.succeeded(), status);
+            result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status);
             Log.i(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage());
             
         } catch (Exception e) {
             Log.i(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage());
             
         } catch (Exception e) {