Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 819b4653 authored by David A. Velasco's avatar David A. Velasco
Browse files

Recovered error when file to copy doesn't exist but still keeping dependency on Context out

parent b281585c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;
+16 −18
Original line number Diff line number Diff line
@@ -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 */
@@ -61,22 +59,29 @@ 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 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;
    }

    /**
     * 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.
+1 −0
Original line number Diff line number Diff line
@@ -397,6 +397,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity>

        // copy a folder into a descendant
        copyOperation = new CopyRemoteFileOperation(
                getContext(),
                SRC_BASE_FOLDER,
                SRC_PATH_TO_EMPTY_FOLDER,
                false