mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
fix created snack bar showing up
This commit is contained in:
parent
0387ceb1d4
commit
af5228a425
@ -0,0 +1,29 @@
|
||||
package com.owncloud.android.lib.common.http.methods.webdav;
|
||||
|
||||
import at.bitfire.dav4android.exception.UnauthorizedException;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class MoveMethod extends DavMethod {
|
||||
final String destinationUrl;
|
||||
final boolean forceOverride;
|
||||
|
||||
public MoveMethod(HttpUrl httpUrl, String destinationUrl, boolean forceOverride) {
|
||||
super(httpUrl);
|
||||
this.destinationUrl = destinationUrl;
|
||||
this.forceOverride = forceOverride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() throws Exception {
|
||||
try {
|
||||
mDavResource.move(destinationUrl, forceOverride);
|
||||
|
||||
mRequest = mDavResource.getRequest();
|
||||
mResponse = mDavResource.getResponse();
|
||||
|
||||
} catch (UnauthorizedException davException) {
|
||||
// Do nothing, we will use the 401 code to handle the situation
|
||||
}
|
||||
return super.getStatusCode();
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.files;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
@ -35,11 +36,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.DavException;
|
||||
import org.apache.jackrabbit.webdav.MultiStatusResponse;
|
||||
import org.apache.jackrabbit.webdav.Status;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
@ -114,9 +110,12 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
||||
HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
mOverwrite);
|
||||
//TODO: apply timeout
|
||||
final int status = client.executeHttpMethod(copyMethod);
|
||||
|
||||
if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) {
|
||||
if(status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
} else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) {
|
||||
|
||||
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||
client.exhaustResponse(copyMethod.getResponseAsStream());
|
||||
|
@ -30,17 +30,20 @@ import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.DavException;
|
||||
import org.apache.jackrabbit.webdav.MultiStatusResponse;
|
||||
import org.apache.jackrabbit.webdav.Status;
|
||||
import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.MoveMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
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.status.OwnCloudVersion;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
|
||||
/**
|
||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||
@ -109,32 +112,29 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
|
||||
|
||||
/// perform remote operation
|
||||
MoveMethod move = null;
|
||||
RemoteOperationResult result = null;
|
||||
try {
|
||||
move = new MoveMethod(
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath),
|
||||
final MoveMethod move = new MoveMethod(
|
||||
HttpUrl.parse( client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
mOverwrite
|
||||
);
|
||||
int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT);
|
||||
|
||||
mOverwrite);
|
||||
//int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT);
|
||||
final int status = client.executeHttpMethod(move);
|
||||
/// process response
|
||||
if (status == HttpStatus.SC_MULTI_STATUS) {
|
||||
result = processPartialError(move);
|
||||
|
||||
if(isSuccess(status)) {
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
} else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) {
|
||||
|
||||
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||
client.exhaustResponse(move.getResponseAsStream());
|
||||
|
||||
|
||||
/// for other errors that could be explicitly handled, check first:
|
||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||
|
||||
} else {
|
||||
result = new RemoteOperationResult(isSuccess(status), move);
|
||||
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||
result = new RemoteOperationResult(move);
|
||||
client.exhaustResponse(move.getResponseAsStream());
|
||||
}
|
||||
|
||||
Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||
@ -145,63 +145,13 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||
result.getLogMessage(), e);
|
||||
|
||||
} finally {
|
||||
if (move != null)
|
||||
move.releaseConnection();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Analyzes a multistatus response from the OC server to generate an appropriate result.
|
||||
* <p>
|
||||
* In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some
|
||||
* children are moved, some other aren't.
|
||||
* <p>
|
||||
* According to the WebDAV specification, a multistatus response SHOULD NOT include partial
|
||||
* successes (201, 204) nor for descendants of already failed children (424) in the response
|
||||
* entity. But SHOULD NOT != MUST NOT, so take carefully.
|
||||
*
|
||||
* @param move Move operation just finished with a multistatus response
|
||||
* @throws IOException If the response body could not be parsed
|
||||
* @throws DavException If the status code is other than MultiStatus or if obtaining
|
||||
* the response XML document fails
|
||||
* @return A result for the {@link MoveRemoteFileOperation} caller
|
||||
*/
|
||||
private RemoteOperationResult processPartialError(MoveMethod move)
|
||||
throws IOException, DavException {
|
||||
// Adding a list of failed descendants to the result could be interesting; or maybe not.
|
||||
// For the moment, let's take the easy way.
|
||||
|
||||
/// check that some error really occurred
|
||||
MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses();
|
||||
Status[] status = null;
|
||||
boolean failFound = false;
|
||||
for (int i = 0; i < responses.length && !failFound; i++) {
|
||||
status = responses[i].getStatus();
|
||||
failFound = (
|
||||
status != null &&
|
||||
status.length > 0 &&
|
||||
status[0].getStatusCode() > 299
|
||||
);
|
||||
}
|
||||
|
||||
RemoteOperationResult result;
|
||||
if (failFound) {
|
||||
result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE);
|
||||
} else {
|
||||
result = new RemoteOperationResult(true, move);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected boolean isSuccess(int status) {
|
||||
return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT;
|
||||
return status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,13 +24,11 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
import android.os.RemoteException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.MoveMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
@ -38,6 +36,11 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import org.apache.commons.httpclient.HttpState;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
|
||||
/**
|
||||
* Remote operation performing the rename of a remote file or folder in the ownCloud server.
|
||||
@ -90,7 +93,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
|
||||
LocalMoveMethod move = null;
|
||||
MoveMethod move = null;
|
||||
|
||||
OwnCloudVersion version = client.getOwnCloudVersion();
|
||||
boolean versionWithForbiddenChars =
|
||||
@ -107,15 +110,20 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||
}
|
||||
|
||||
move = new LocalMoveMethod(client.getWebdavUri() +
|
||||
WebdavUtils.encodePath(mOldRemotePath),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
|
||||
client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
|
||||
result = new RemoteOperationResult(move.succeeded(), move);
|
||||
move = new MoveMethod(HttpUrl.parse(client.getWebdavUri() +
|
||||
WebdavUtils.encodePath(mOldRemotePath)),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
||||
//TODO: client.execute(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
|
||||
final int status = client.executeHttpMethod(move);
|
||||
if(status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
} else {
|
||||
result = new RemoteOperationResult(move);
|
||||
}
|
||||
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " +
|
||||
result.getLogMessage()
|
||||
);
|
||||
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||
client.exhaustResponse(move.getResponseAsStream());
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
@ -123,9 +131,6 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " +
|
||||
result.getLogMessage(), e);
|
||||
|
||||
} finally {
|
||||
if (move != null)
|
||||
move.releaseConnection();
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -147,26 +152,4 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
return exists.isSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move operation
|
||||
*/
|
||||
private class LocalMoveMethod extends DavMethodBase {
|
||||
|
||||
public LocalMoveMethod(String uri, String dest) {
|
||||
super(uri);
|
||||
addRequestHeader(new org.apache.commons.httpclient.Header("Destination", dest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "MOVE";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSuccess(int status) {
|
||||
return status == 201 || status == 204;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user