X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a8b46b7d95bf9cfc8fd09fa5eff1229dcc6d5208..eb2d8e28dc01abcb45a95002268e74db39befe3f:/src/com/owncloud/android/operations/UnshareLinkOperation.java diff --git a/src/com/owncloud/android/operations/UnshareLinkOperation.java b/src/com/owncloud/android/operations/UnshareLinkOperation.java index 69fa5961..6e273c87 100644 --- a/src/com/owncloud/android/operations/UnshareLinkOperation.java +++ b/src/com/owncloud/android/operations/UnshareLinkOperation.java @@ -17,12 +17,15 @@ package com.owncloud.android.operations; +import android.content.Context; + import com.owncloud.android.datamodel.OCFile; 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.ExistenceCheckRemoteOperation; +import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.Log_OC; @@ -37,9 +40,12 @@ public class UnshareLinkOperation extends SyncOperation { private static final String TAG = UnshareLinkOperation.class.getSimpleName(); private OCFile mFile; + private Context mContext; + - public UnshareLinkOperation(OCFile file) { + public UnshareLinkOperation(OCFile file, Context context) { mFile = file; + mContext = context; } @Override @@ -54,10 +60,10 @@ public class UnshareLinkOperation extends SyncOperation { 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); @@ -65,12 +71,26 @@ public class UnshareLinkOperation extends SyncOperation { getStorageManager().saveFile(mFile); getStorageManager().removeShare(share); - } + if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { + if (existsFile(client, mFile.getRemotePath())) { + result = new RemoteOperationResult(ResultCode.OK); + } else { + getStorageManager().removeFile(mFile, true, true); + } + } + } + } else { - result = new RemoteOperationResult(ResultCode.FILE_NOT_FOUND); + result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND); } return result; } + + private boolean existsFile(OwnCloudClient client, String remotePath){ + ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false); + RemoteOperationResult result = existsOperation.execute(client); + return result.isSuccess(); + } }