mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Change HEAD method to PROPFIND method while checking path existence before starting an upload
This commit is contained in:
parent
21d1265ca5
commit
06f907294a
@ -58,6 +58,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName();
|
private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName();
|
||||||
private static final int FORBIDDEN_ERROR = 403;
|
private static final int FORBIDDEN_ERROR = 403;
|
||||||
|
private static final int SERVICE_UNAVAILABLE_ERROR = 503;
|
||||||
|
|
||||||
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
|
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
|
||||||
private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
|
private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
|
||||||
@ -162,7 +163,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
|||||||
// TODO some kind of error control!
|
// TODO some kind of error control!
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (status != FORBIDDEN_ERROR){
|
} else if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR){
|
||||||
client.exhaustResponse(mGet.getResponseBodyAsStream());
|
client.exhaustResponse(mGet.getResponseBodyAsStream());
|
||||||
|
|
||||||
} // else, body read by RemoteOeprationResult constructor
|
} // else, body read by RemoteOeprationResult constructor
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
package com.owncloud.android.lib.resources.files;
|
package com.owncloud.android.lib.resources.files;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.methods.HeadMethod;
|
import org.apache.jackrabbit.webdav.DavConstants;
|
||||||
|
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@ -48,6 +49,9 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
|
|
||||||
private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName();
|
private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final int FORBIDDEN_ERROR = 403;
|
||||||
|
private static final int SERVICE_UNAVAILABLE_ERROR = 503;
|
||||||
|
|
||||||
private String mPath;
|
private String mPath;
|
||||||
private boolean mSuccessIfAbsent;
|
private boolean mSuccessIfAbsent;
|
||||||
|
|
||||||
@ -83,24 +87,32 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
HeadMethod head = null;
|
PropFindMethod propfind = null;
|
||||||
boolean previousFollowRedirects = client.getFollowRedirects();
|
boolean previousFollowRedirects = client.getFollowRedirects();
|
||||||
try {
|
try {
|
||||||
head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath));
|
propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath),
|
||||||
|
WebdavUtils.getAllPropSet(), DavConstants.DEPTH_0);
|
||||||
client.setFollowRedirects(false);
|
client.setFollowRedirects(false);
|
||||||
int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
|
int status = client.executeMethod(propfind, TIMEOUT, TIMEOUT);
|
||||||
if (previousFollowRedirects) {
|
if (previousFollowRedirects) {
|
||||||
mRedirectionPath = client.followRedirection(head);
|
mRedirectionPath = client.followRedirection(propfind);
|
||||||
status = mRedirectionPath.getLastStatus();
|
status = mRedirectionPath.getLastStatus();
|
||||||
}
|
}
|
||||||
client.exhaustResponse(head.getResponseBodyAsStream());
|
if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR) {
|
||||||
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) ||
|
client.exhaustResponse(propfind.getResponseBodyAsStream());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* PROPFIND method
|
||||||
|
* 404 NOT FOUND: path doesn't exist,
|
||||||
|
* 207 MULTI_STATUS: path exists.
|
||||||
|
*/
|
||||||
|
boolean success = ((status == HttpStatus.SC_OK || status == HttpStatus.SC_MULTI_STATUS) &&
|
||||||
|
!mSuccessIfAbsent) ||
|
||||||
|
(status == HttpStatus.SC_MULTI_STATUS && !mSuccessIfAbsent) ||
|
||||||
(status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
|
(status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
|
||||||
result = new RemoteOperationResult(
|
result = new RemoteOperationResult(
|
||||||
success,
|
success,
|
||||||
status,
|
propfind
|
||||||
head.getStatusText(),
|
|
||||||
head.getResponseHeaders()
|
|
||||||
);
|
);
|
||||||
Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() +
|
Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() +
|
||||||
WebdavUtils.encodePath(mPath) + " targeting for " +
|
WebdavUtils.encodePath(mPath) + " targeting for " +
|
||||||
@ -115,8 +127,8 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
result.getLogMessage(), result.getException());
|
result.getLogMessage(), result.getException());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (head != null)
|
if (propfind != null)
|
||||||
head.releaseConnection();
|
propfind.releaseConnection();
|
||||||
client.setFollowRedirects(previousFollowRedirects);
|
client.setFollowRedirects(previousFollowRedirects);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user