From 819b4653853ed26f3e427118437af39c9b42d651 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 18 Aug 2015 14:07:59 +0200 Subject: [PATCH] Recovered error when file to copy doesn't exist but still keeping dependency on Context out --- .../files/CopyRemoteFileOperation.java | 4 +++ .../files/ExistenceCheckRemoteOperation.java | 36 +++++++++---------- .../lib/test_project/test/CopyFileTest.java | 1 + 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java index f9f9d346..38bdcf5a 100644 --- a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java @@ -105,6 +105,10 @@ public class CopyRemoteFileOperation extends RemoteOperation { 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 CopyMethod copyMethod = null; RemoteOperationResult result = null; diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 71a2e46f..e6a4b73c 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -28,7 +28,6 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.HeadMethod; import android.content.Context; -import android.net.ConnectivityManager; import com.owncloud.android.lib.common.OwnCloudClient; 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 String mPath; - private Context mContext; private boolean mSuccessIfAbsent; /** 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. - * - * @param remotePath Path to append to the URL owned by the client instance. - * @param context Android application context. + * + * @param remotePath Path to append to the URL owned by the client instance. * @param successIfAbsent When 'true', the operation finishes in success if the path does * 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 : ""; - mContext = context; 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) { - if (!isOnline()) { - return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); - } RemoteOperationResult result = null; HeadMethod head = null; boolean previousFollowRedirects = client.getFollowRedirects(); @@ -112,13 +117,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { 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. diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java index 468d2de1..e7f84003 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java @@ -397,6 +397,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2 // copy a folder into a descendant copyOperation = new CopyRemoteFileOperation( + getContext(), SRC_BASE_FOLDER, SRC_PATH_TO_EMPTY_FOLDER, false