Merge branch 'develop' into share_link__unshare_file
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / UnshareLinkOperation.java
index c588ec1..ad23427 100644 (file)
@@ -22,7 +22,7 @@ import com.owncloud.android.lib.network.OwnCloudClient;
 import com.owncloud.android.lib.operations.common.OCShare;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
-import com.owncloud.android.lib.operations.remote.UnshareLinkRemoteOperation;
+import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.utils.Log_OC;
 
@@ -47,13 +47,17 @@ public class UnshareLinkOperation extends SyncOperation {
         RemoteOperationResult result  = null;
         
         // Get Share for a file
-        OCShare share = getStorageManager().getShareByPath(mFile.getRemotePath());
+        String path = mFile.getRemotePath();
+        if (mFile.isFolder()) {
+            path = path.substring(0, path.length()-1); // Remove last /
+        }
+        OCShare share = getStorageManager().getShareByPath(path);
         
         if (share != null) {
-            UnshareLinkRemoteOperation operation = new UnshareLinkRemoteOperation((int) share.getIdRemoteShared());
+            RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
             result = operation.execute(client);
 
-            if (result.isSuccess()) {
+            if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
                 Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
 
                 mFile.setShareByLink(false);
@@ -61,9 +65,13 @@ public class UnshareLinkOperation extends SyncOperation {
                 getStorageManager().saveFile(mFile);
                 getStorageManager().removeShare(share);
                 
-            }
+                if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+                    result = new RemoteOperationResult(ResultCode.OK);
+                }
+            } 
+                
         } else {
-            result = new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
+            result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
         }
 
         return result;