OSDN Git Service

Fix getFileInfo calls. The return of this function must be checked
authorjruesga <jorge@ruesga.com>
Sun, 21 Oct 2012 13:52:59 +0000 (15:52 +0200)
committerjruesga <jorge@ruesga.com>
Sun, 21 Oct 2012 13:52:59 +0000 (15:52 +0200)
src/com/cyanogenmod/explorer/activities/NavigationActivity.java
src/com/cyanogenmod/explorer/activities/SearchActivity.java
src/com/cyanogenmod/explorer/ui/policy/CompressActionPolicy.java
src/com/cyanogenmod/explorer/ui/policy/CopyMoveActionPolicy.java
src/com/cyanogenmod/explorer/ui/policy/DeleteActionPolicy.java
src/com/cyanogenmod/explorer/ui/policy/NewActionPolicy.java
tests/src/com/cyanogenmod/explorer/commands/shell/LinkCommandTest.java

index 0f5c3cd..e106baa 100644 (file)
@@ -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
index ad7f4f0..32aeb9a 100644 (file)
@@ -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
index 54fe653..345bcd4 100644 (file)
@@ -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(
index b8de116..2c1fa25 100644 (file)
@@ -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);
index 8e0aa36..39d1a32 100644 (file)
@@ -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
index fd29fbe..d92681e 100644 (file)
@@ -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;
index 2e0281b..cf7e8a6 100644 (file)
@@ -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 {