From 57f69dcee99db89d14bc37f7aad45b38dfb5ce63 Mon Sep 17 00:00:00 2001 From: jruesga Date: Sun, 21 Oct 2012 15:52:59 +0200 Subject: [PATCH] Fix getFileInfo calls. The return of this function must be checked --- .../explorer/activities/NavigationActivity.java | 3 ++ .../explorer/activities/SearchActivity.java | 3 ++ .../explorer/ui/policy/CompressActionPolicy.java | 33 ++++++++++++++-------- .../explorer/ui/policy/CopyMoveActionPolicy.java | 7 ++++- .../explorer/ui/policy/DeleteActionPolicy.java | 9 ++++-- .../explorer/ui/policy/NewActionPolicy.java | 15 +++------- .../explorer/commands/shell/LinkCommandTest.java | 1 + 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java index 0f5c3cd..e106baa 100644 --- a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java +++ b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java @@ -1227,6 +1227,9 @@ public class NavigationActivity extends Activity FileSystemObject fso = null; try { fso = CommandHelper.getFileInfo(this, path, false, null); + if (fso == null) { + throw new NoSuchFileOrDirectory(path); + } } catch (Exception e) { // Notify the user diff --git a/src/com/cyanogenmod/explorer/activities/SearchActivity.java b/src/com/cyanogenmod/explorer/activities/SearchActivity.java index ad7f4f0..32aeb9a 100644 --- a/src/com/cyanogenmod/explorer/activities/SearchActivity.java +++ b/src/com/cyanogenmod/explorer/activities/SearchActivity.java @@ -856,6 +856,9 @@ public class SearchActivity extends Activity FileSystemObject fso = null; try { fso = CommandHelper.getFileInfo(this, item.getFullPath(), false, null); + if (fso == null) { + throw new NoSuchFileOrDirectory(item.getFullPath()); + } } catch (Exception e) { // Notify the user diff --git a/src/com/cyanogenmod/explorer/ui/policy/CompressActionPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/CompressActionPolicy.java index 54fe653..345bcd4 100644 --- a/src/com/cyanogenmod/explorer/ui/policy/CompressActionPolicy.java +++ b/src/com/cyanogenmod/explorer/ui/policy/CompressActionPolicy.java @@ -406,16 +406,20 @@ public final class CompressActionPolicy extends ActionsPolicy { throw this.mListener.mCause; } - // Check that the operation was completed retrieving the extracted file or folder - boolean failed = true; + // Check that the operation was completed retrieving the compressed file or folder + boolean failed = false; try { - CommandHelper.getFileInfo(ctx, out, false, null); + FileSystemObject fso = CommandHelper.getFileInfo(ctx, out, false, null); + if (fso == null) { + // Failed. The file or folder not exists + failed = true; + } - // Failed. The file exists - failed = false; + // Operation complete successfully } catch (Throwable e) { - // Operation complete successfully + // Failed. The file or folder not exists + failed = true; } if (failed) { throw new ExecutionException( @@ -655,16 +659,21 @@ public final class CompressActionPolicy extends ActionsPolicy { throw this.mListener.mCause; } - // Check that the operation was completed retrieving the extracted file or folder - boolean failed = true; + // Check that the operation was completed retrieving the uncompressed + // file or folder + boolean failed = false; try { - CommandHelper.getFileInfo(ctx, out, false, null); + FileSystemObject fso2 = CommandHelper.getFileInfo(ctx, out, false, null); + if (fso2 == null) { + // Failed. The file or folder not exists + failed = true; + } - // Failed. The file exists - failed = false; + // Operation complete successfully } catch (Throwable e) { - // Operation complete successfully + // Failed. The file or folder not exists + failed = true; } if (failed) { throw new ExecutionException( diff --git a/src/com/cyanogenmod/explorer/ui/policy/CopyMoveActionPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/CopyMoveActionPolicy.java index b8de116..2c1fa25 100644 --- a/src/com/cyanogenmod/explorer/ui/policy/CopyMoveActionPolicy.java +++ b/src/com/cyanogenmod/explorer/ui/policy/CopyMoveActionPolicy.java @@ -23,6 +23,7 @@ import android.text.Html; import android.text.Spanned; import com.cyanogenmod.explorer.R; +import com.cyanogenmod.explorer.console.NoSuchFileOrDirectory; import com.cyanogenmod.explorer.console.RelaunchableException; import com.cyanogenmod.explorer.listeners.OnRequestRefreshListener; import com.cyanogenmod.explorer.listeners.OnSelectionListener; @@ -405,7 +406,11 @@ public final class CopyMoveActionPolicy extends ActionsPolicy { } // Check that the operation was completed retrieving the fso modified - CommandHelper.getFileInfo(ctx, dst.getAbsolutePath(), false, null); + FileSystemObject fso = + CommandHelper.getFileInfo(ctx, dst.getAbsolutePath(), false, null); + if (fso == null) { + throw new NoSuchFileOrDirectory(dst.getAbsolutePath()); + } } }; final BackgroundAsyncTask task = new BackgroundAsyncTask(ctx, callable); diff --git a/src/com/cyanogenmod/explorer/ui/policy/DeleteActionPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/DeleteActionPolicy.java index 8e0aa36..39d1a32 100644 --- a/src/com/cyanogenmod/explorer/ui/policy/DeleteActionPolicy.java +++ b/src/com/cyanogenmod/explorer/ui/policy/DeleteActionPolicy.java @@ -262,9 +262,12 @@ public final class DeleteActionPolicy extends ActionsPolicy { boolean failed = false; try { CommandHelper.getFileInfo(ctx, fso.getFullPath(), false, null); - - // Failed. The file still exists - failed = true; + FileSystemObject fso2 = + CommandHelper.getFileInfo(ctx, fso.getFullPath(), false, null); + if (fso2 != null) { + // Failed. The file still exists + failed = true; + } } catch (Throwable e) { // Operation complete successfully diff --git a/src/com/cyanogenmod/explorer/ui/policy/NewActionPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/NewActionPolicy.java index fd29fbe..d92681e 100644 --- a/src/com/cyanogenmod/explorer/ui/policy/NewActionPolicy.java +++ b/src/com/cyanogenmod/explorer/ui/policy/NewActionPolicy.java @@ -109,9 +109,7 @@ public final class NewActionPolicy extends ActionsPolicy { FileSystemObject fso = null; try { fso = CommandHelper.getFileInfo(ctx, newName, false, null); - } catch (Throwable ex2) { - /**NON BLOCK**/ - } + } catch (Throwable ex2) {/**NON BLOCK**/} onRequestRefreshListener.onRequestRefresh(fso); } showOperationSuccessMsg(ctx); @@ -129,11 +127,8 @@ public final class NewActionPolicy extends ActionsPolicy { if (onRequestRefreshListener != null) { FileSystemObject fso = null; try { - fso = - CommandHelper.getFileInfo(ctx, newName, false, null); - } catch (Throwable ex2) { - /**NON BLOCK**/ - } + fso = CommandHelper.getFileInfo(ctx, newName, false, null); + } catch (Throwable ex2) {/**NON BLOCK**/} onRequestRefreshListener.onRequestRefresh(fso); } return Boolean.TRUE; @@ -208,9 +203,7 @@ public final class NewActionPolicy extends ActionsPolicy { FileSystemObject fso = null; try { fso = CommandHelper.getFileInfo(ctx, link, false, null); - } catch (Throwable ex2) { - /**NON BLOCK**/ - } + } catch (Throwable ex2) {/**NON BLOCK**/} onRequestRefreshListener.onRequestRefresh(fso); } return Boolean.TRUE; diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/LinkCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/LinkCommandTest.java index 2e0281b..cf7e8a6 100644 --- a/tests/src/com/cyanogenmod/explorer/commands/shell/LinkCommandTest.java +++ b/tests/src/com/cyanogenmod/explorer/commands/shell/LinkCommandTest.java @@ -64,6 +64,7 @@ public class LinkCommandTest extends AbstractConsoleTest { FileSystemObject fso = CommandHelper.getFileInfo(getContext(), PATH_LINK_OK, false, getConsole()); assertTrue("response==false", ret); //$NON-NLS-1$ + assertNotNull("fso==null", fso); //$NON-NLS-1$ assertTrue("fso not is Symlink", fso instanceof Symlink); //$NON-NLS-1$ } finally { try { -- 2.11.0