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;
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);
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;