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

Commit ac44c199 authored by Matt Garnes's avatar Matt Garnes
Browse files

Inform the user if copy/move fails with no space remaining.

- Detect the specific IOException representing no space left on the
  device. Throw an ExecutionException for this particular case.
- Support translatable ExecutionExceptions that specify a string
  resource as a message.

Change-Id: I798cc3c194b78d3a2d13685d29cfbb580de3f30e
parent c21b4b78
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,8 @@
    <!-- When an operation requires elevated privileged (normally caused for the use of a
         non-privileged console) -->
    <string name="msgs_insufficient_permissions">This operation requires elevated permissions. Try changing to Root Access mode.</string>
    <!-- When an operation fails because the device has run out of storage. -->
    <string name="msgs_no_disk_space">This operation failed because there is no space left on the device.</string>
    <!-- The file or directory was not found -->
    <string name="msgs_file_not_found">The file or folder was not found.</string>
    <!-- The command reference couldn't be created (not found or invalid definition)
+19 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ public class ExecutionException extends Exception {

    private static final long serialVersionUID = 5900809383615958749L;

    private int mDetailMessageResId = 0;

    /**
     * Constructor of <code>ExecutionException</code>.
     *
@@ -32,6 +34,16 @@ public class ExecutionException extends Exception {
        super(detailMessage);
    }

    /**
     * Constructor of <code>ExecutionException</code>.
     *
     * @param detailMessageResId Res ID for Message associated to the exception
     */
    public ExecutionException(int detailMessageResId) {
        super();
        mDetailMessageResId = detailMessageResId;
    }

    /**
     * Constructor of <code>ExecutionException</code>.
     *
@@ -42,4 +54,11 @@ public class ExecutionException extends Exception {
        super(detailMessage, throwable);
    }

    /**
     * Returns the res ID that has been set to represent this error's message. Used for translation.
     * @return The string resource id of this Exception's message.
     */
    public int getDetailMessageResId() {
        return mDetailMessageResId;
    }
}
+15 −7
Original line number Diff line number Diff line
@@ -194,6 +194,13 @@ public final class ExceptionUtil {
        //Get the appropriate message for the exception
        int msgResId = R.string.msgs_unknown;
        boolean toast = true;

        // If an ExecutionException has specified a resource string to use,
        // this is a special case and should be displayed as such.
        if ((ex instanceof ExecutionException)
            && ((ExecutionException)ex).getDetailMessageResId() != 0) {
            msgResId = ((ExecutionException)ex).getDetailMessageResId();
        } else {
            int cc = KNOWN_EXCEPTIONS.length;
            for (int i = 0; i < cc; i++) {
                if (KNOWN_EXCEPTIONS[i].getCanonicalName().compareTo(
@@ -203,6 +210,7 @@ public final class ExceptionUtil {
                    break;
                }
            }
        }

        //Check exceptions that can be asked to user
        if (ex instanceof RelaunchableException && askUser) {
+12 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.cyanogenmod.filemanager.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.system.ErrnoException;
import android.system.OsConstants;
import android.util.Log;

import com.cyanogenmod.filemanager.FileManagerApplication;
@@ -1053,7 +1055,8 @@ public final class FileHelper {
     * @param bufferSize The buffer size for the operation
     * @return boolean If the operation complete successfully
     */
    public static boolean bufferedCopy(final File src, final File dst, int bufferSize) {
    public static boolean bufferedCopy(final File src, final File dst,
        int bufferSize) throws ExecutionException {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
@@ -1069,6 +1072,14 @@ public final class FileHelper {
        } catch (Throwable e) {
            Log.e(TAG,
                    String.format(TAG, "Failed to copy from %s to %d", src, dst), e); //$NON-NLS-1$

            // Check if this error is an out of space exception and throw that specifically.
            // ENOSPC -> Error No Space
            if (e.getCause() instanceof ErrnoException
                        && ((ErrnoException)e.getCause()).errno == OsConstants.ENOSPC) {
                throw new ExecutionException(R.string.msgs_no_disk_space);
            }

            return false;
        } finally {
            try {