mirror of
https://github.com/owncloud/android-library.git
synced 2025-07-23 18:06:17 +00:00
Recovered error when file to copy doesn't exist but still keeping dependency on Context out
This commit is contained in:
parent
b281585c93
commit
819b465385
@ -105,6 +105,10 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!new ExistenceCheckRemoteOperation(mSrcRemotePath, Boolean.FALSE).run(getClient()).isSuccess()) {
|
||||||
|
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
CopyMethod copyMethod = null;
|
CopyMethod copyMethod = null;
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
|
@ -28,7 +28,6 @@ import org.apache.commons.httpclient.HttpStatus;
|
|||||||
import org.apache.commons.httpclient.methods.HeadMethod;
|
import org.apache.commons.httpclient.methods.HeadMethod;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.network.RedirectionPath;
|
import com.owncloud.android.lib.common.network.RedirectionPath;
|
||||||
@ -50,7 +49,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName();
|
private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName();
|
||||||
|
|
||||||
private String mPath;
|
private String mPath;
|
||||||
private Context mContext;
|
|
||||||
private boolean mSuccessIfAbsent;
|
private boolean mSuccessIfAbsent;
|
||||||
|
|
||||||
/** Sequence of redirections followed. Available only after executing the operation */
|
/** Sequence of redirections followed. Available only after executing the operation */
|
||||||
@ -59,24 +57,31 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Full constructor. Success of the operation will depend upon the value of successIfAbsent.
|
* Full constructor. Success of the operation will depend upon the value of successIfAbsent.
|
||||||
*
|
*
|
||||||
* @param remotePath Path to append to the URL owned by the client instance.
|
* @param remotePath Path to append to the URL owned by the client instance.
|
||||||
* @param context Android application context.
|
|
||||||
* @param successIfAbsent When 'true', the operation finishes in success if the path does
|
* @param successIfAbsent When 'true', the operation finishes in success if the path does
|
||||||
* NOT exist in the remote server (HTTP 404).
|
* NOT exist in the remote server (HTTP 404).
|
||||||
*/
|
*/
|
||||||
public ExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent) {
|
public ExistenceCheckRemoteOperation(String remotePath, boolean successIfAbsent) {
|
||||||
mPath = (remotePath != null) ? remotePath : "";
|
mPath = (remotePath != null) ? remotePath : "";
|
||||||
mContext = context;
|
|
||||||
mSuccessIfAbsent = successIfAbsent;
|
mSuccessIfAbsent = successIfAbsent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Full constructor. Success of the operation will depend upon the value of successIfAbsent.
|
||||||
|
*
|
||||||
|
* @param remotePath Path to append to the URL owned by the client instance.
|
||||||
|
* @param context Android application context.
|
||||||
|
* @param successIfAbsent When 'true', the operation finishes in success if the path does
|
||||||
|
* NOT exist in the remote server (HTTP 404).
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public ExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent) {
|
||||||
|
this(remotePath, successIfAbsent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
if (!isOnline()) {
|
|
||||||
return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
|
|
||||||
}
|
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
HeadMethod head = null;
|
HeadMethod head = null;
|
||||||
boolean previousFollowRedirects = client.getFollowRedirects();
|
boolean previousFollowRedirects = client.getFollowRedirects();
|
||||||
@ -112,13 +117,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOnline() {
|
|
||||||
ConnectivityManager cm = (ConnectivityManager) mContext
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
return cm != null && cm.getActiveNetworkInfo() != null
|
|
||||||
&& cm.getActiveNetworkInfo().isConnectedOrConnecting();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the sequence of redirections followed during the execution of the operation.
|
* Gets the sequence of redirections followed during the execution of the operation.
|
||||||
|
@ -397,6 +397,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>
|
|||||||
|
|
||||||
// copy a folder into a descendant
|
// copy a folder into a descendant
|
||||||
copyOperation = new CopyRemoteFileOperation(
|
copyOperation = new CopyRemoteFileOperation(
|
||||||
|
getContext(),
|
||||||
SRC_BASE_FOLDER,
|
SRC_BASE_FOLDER,
|
||||||
SRC_PATH_TO_EMPTY_FOLDER,
|
SRC_PATH_TO_EMPTY_FOLDER,
|
||||||
false
|
false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user