aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjruesga <jorge@ruesga.com>2012-10-10 02:59:21 +0200
committerjruesga <jorge@ruesga.com>2012-10-10 02:59:21 +0200
commitd94a0a07b0b7813c96057ef6083e3fbdeff7d562 (patch)
tree10f7a97eb187d858e3beff40b51386d5113661ce
parent4e363cc84a40957a9b45d6ec3220c94d164c7953 (diff)
downloadandroid_packages_apps_CMFileManager-d94a0a07b0b7813c96057ef6083e3fbdeff7d562.tar.gz
android_packages_apps_CMFileManager-d94a0a07b0b7813c96057ef6083e3fbdeff7d562.tar.bz2
android_packages_apps_CMFileManager-d94a0a07b0b7813c96057ef6083e3fbdeff7d562.zip
Better symlinks handle
Resolve symlinks with -> symbols in any of the names (link or real).
-rw-r--r--res/xml/command_list.xml2
-rw-r--r--src/com/cyanogenmod/explorer/activities/NavigationActivity.java2
-rw-r--r--src/com/cyanogenmod/explorer/activities/SearchActivity.java2
-rw-r--r--src/com/cyanogenmod/explorer/commands/ExecutableCreator.java15
-rw-r--r--src/com/cyanogenmod/explorer/commands/shell/FindCommand.java6
-rw-r--r--src/com/cyanogenmod/explorer/commands/shell/ListCommand.java135
-rw-r--r--src/com/cyanogenmod/explorer/commands/shell/ResolveLinkCommand.java2
-rw-r--r--src/com/cyanogenmod/explorer/commands/shell/ShellExecutableCreator.java20
-rw-r--r--src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java9
-rw-r--r--src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java8
-rw-r--r--src/com/cyanogenmod/explorer/util/CommandHelper.java40
-rw-r--r--src/com/cyanogenmod/explorer/util/FileHelper.java4
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/ChangeOwnerCommandTest.java4
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/ChangePermissionsCommandTest.java4
-rw-r--r--tests/src/com/cyanogenmod/explorer/commands/shell/ListCommandTest.java3
15 files changed, 182 insertions, 74 deletions
diff --git a/res/xml/command_list.xml b/res/xml/command_list.xml
index 06d3759b..d8b1f322 100644
--- a/res/xml/command_list.xml
+++ b/res/xml/command_list.xml
@@ -49,7 +49,7 @@
<command commandId="folderusage" commandPath="/system/bin/ls" commandArgs="-alR %1$s" />
<command commandId="groups" commandPath="/system/xbin/groups" commandArgs="" />
<command commandId="id" commandPath="/system/bin/id" commandArgs="-Gn" />
- <command commandId="ls" commandPath="cd" commandArgs="%1$s &amp;&amp; /system/bin/ls -al %1$s | /system/xbin/grep -v -e '->' &amp;&amp; echo '>SIMLINKS>' &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -e '->' || true; } &amp;&amp; echo '>SIMLINKS_DATA>' &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/awk '{print $2}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f &amp;&amp; /system/bin/ls -F %1$s | /system/xbin/grep -e '^l' | /system/xbin/awk '{print $2}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f | { /system/xbin/xargs -r -n1 /system/bin/ls -ald || true; }" />
+ <command commandId="ls" commandPath="cd" commandArgs="%1$s &amp;&amp; /system/bin/ls -al %1$s | /system/xbin/grep -v -e '->' &amp;&amp; echo '>SIMLINKS>' &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -e '->' || true; } &amp;&amp; echo '>SIMLINKS_DATA>' &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/awk '{print substr($0, index($0,$2))}' | /system/xbin/xargs -r -0 /system/xbin/readlink -f &amp;&amp; /system/bin/ls -F %1$s | /system/xbin/grep -e '^l' | /system/xbin/awk '{print substr($0, index($0,$2))}' | /system/xbin/xargs -r -0 /system/xbin/readlink -f | { /system/xbin/xargs -r -0 /system/bin/ls -ald || echo; }" />
<command commandId="mkdir" commandPath="/system/bin/mkdir" commandArgs="%1$s" />
<command commandId="mount" commandPath="/system/bin/mount" commandArgs="-o %1$s,remount -t auto %2$s %3$s" />
<command commandId="mountpointinfo" commandPath="/system/bin/cat" commandArgs="/proc/mounts" />
diff --git a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java
index 6fda50d7..16ba3036 100644
--- a/src/com/cyanogenmod/explorer/activities/NavigationActivity.java
+++ b/src/com/cyanogenmod/explorer/activities/NavigationActivity.java
@@ -1154,7 +1154,7 @@ public class NavigationActivity extends Activity
// Prior to show the dialog, refresh the item reference
FileSystemObject fso = null;
try {
- fso = CommandHelper.getFileInfo(this, path, null);
+ fso = CommandHelper.getFileInfo(this, path, false, null);
} 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 8383b989..6bac73b2 100644
--- a/src/com/cyanogenmod/explorer/activities/SearchActivity.java
+++ b/src/com/cyanogenmod/explorer/activities/SearchActivity.java
@@ -851,7 +851,7 @@ public class SearchActivity extends Activity
// Prior to show the dialog, refresh the item reference
FileSystemObject fso = null;
try {
- fso = CommandHelper.getFileInfo(this, item.getFullPath(), null);
+ fso = CommandHelper.getFileInfo(this, item.getFullPath(), false, null);
} catch (Exception e) {
// Notify the user
diff --git a/src/com/cyanogenmod/explorer/commands/ExecutableCreator.java b/src/com/cyanogenmod/explorer/commands/ExecutableCreator.java
index e024b9e2..2f6703f0 100644
--- a/src/com/cyanogenmod/explorer/commands/ExecutableCreator.java
+++ b/src/com/cyanogenmod/explorer/commands/ExecutableCreator.java
@@ -204,12 +204,23 @@ public interface ExecutableCreator {
* Method that creates an executable for list files of a directory.
*
* @param src The directory where to do the listing
- * @param mode The listing mode
* @return ListExecutable A {@link ListExecutable} executable implementation reference
* @throws CommandNotFoundException If the executable can't be created
* @see LIST_MODE
*/
- ListExecutable createListExecutable(String src, LIST_MODE mode)
+ ListExecutable createListExecutable(String src)
+ throws CommandNotFoundException;
+
+ /**
+ * Method that creates an executable for retrieve information of a file
+ *
+ * @param src The directory where to do the listing
+ * @param followSymlinks If follow the symlink
+ * @return ListExecutable A {@link ListExecutable} executable implementation reference
+ * @throws CommandNotFoundException If the executable can't be created
+ * @see LIST_MODE
+ */
+ ListExecutable createFileInfoExecutable(String src, boolean followSymlinks)
throws CommandNotFoundException;
/**
diff --git a/src/com/cyanogenmod/explorer/commands/shell/FindCommand.java b/src/com/cyanogenmod/explorer/commands/shell/FindCommand.java
index 1fa4b2ea..7a2e3d0a 100644
--- a/src/com/cyanogenmod/explorer/commands/shell/FindCommand.java
+++ b/src/com/cyanogenmod/explorer/commands/shell/FindCommand.java
@@ -144,6 +144,12 @@ public class FindCommand extends AsyncResultProgram implements FindExecutable {
// Don't return the directory of the search. Only files under this
// directory
if (this.mDirectory.compareTo(fso.getFullPath()) != 0) {
+ String name = new File(lines.get(0)).getName();
+ // In some situations, xe when the name has a -> the name is
+ // incorrect resolved, but src name should by fine in this case
+ fso.setName(name);
+ // The symlink is not resolved here
+
this.mFiles.add(fso);
partialFiles.add(fso);
}
diff --git a/src/com/cyanogenmod/explorer/commands/shell/ListCommand.java b/src/com/cyanogenmod/explorer/commands/shell/ListCommand.java
index d2f1b4fc..957fa916 100644
--- a/src/com/cyanogenmod/explorer/commands/shell/ListCommand.java
+++ b/src/com/cyanogenmod/explorer/commands/shell/ListCommand.java
@@ -55,15 +55,15 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
private static final String SYMLINK_REF = ">SIMLINKS>"; //$NON-NLS-1$
private static final String SYMLINK_DATA_REF = ">SIMLINKS_DATA>"; //$NON-NLS-1$
+ private final String mSrc;
private final LIST_MODE mMode;
private final List<FileSystemObject> mFiles;
private String mParentDir;
/**
- * Constructor of <code>ListCommand</code>.
+ * Constructor of <code>ListCommand</code>. List mode.
*
* @param src The file system object to be listed
- * @param mode The listing mode
* @param console The console in which retrieve the parent directory information.
* <code>null</code> to attach to the default console
* @throws InvalidCommandDefinitionException If the command has an invalid definition
@@ -76,54 +76,84 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
* @throws OperationTimeoutException If the operation exceeded the maximum time of wait
* @throws ExecutionException If the operation returns a invalid exit code
*/
- public ListCommand(String src, LIST_MODE mode, ShellConsole console)
+ public ListCommand(String src, ShellConsole console)
throws InvalidCommandDefinitionException, FileNotFoundException,
NoSuchFileOrDirectory, IOException, ConsoleAllocException,
InsufficientPermissionsException, CommandNotFoundException,
OperationTimeoutException, ExecutionException {
//If the mode is listing directory, for avoid problems with symlink,
//always append a / to the end of the path (if not exists)
- super(mode.compareTo(LIST_MODE.DIRECTORY) == 0 ? ID_LS_DIRECTORY : ID_LS_INFO,
- new String[]{
- mode.compareTo(LIST_MODE.DIRECTORY) == 0
- ? FileHelper.addTrailingSlash(src)
- : FileHelper.removeTrailingSlash(src)
- });
+ super(ID_LS_DIRECTORY, new String[]{ FileHelper.addTrailingSlash(src) });
//Initialize files to something distinct of null
this.mFiles = new ArrayList<FileSystemObject>();
- this.mMode = mode;
+ this.mMode = LIST_MODE.DIRECTORY;
+ this.mSrc = src;
//Retrieve parent directory information
- if (mode.compareTo(LIST_MODE.DIRECTORY) == 0) {
- //Resolve the parent directory
- if (src.compareTo(FileHelper.ROOT_DIRECTORY) == 0) {
- this.mParentDir = null;
- } else {
- this.mParentDir =
- CommandHelper.getAbsolutePath(
- ExplorerApplication.
- getInstance().getApplicationContext(), src, console);
- }
+ if (src.compareTo(FileHelper.ROOT_DIRECTORY) == 0) {
+ this.mParentDir = null;
} else {
- //Get the absolute path
- try {
- this.mParentDir =
- FileHelper.removeTrailingSlash(
- new File(src).getCanonicalFile().getParent());
+ this.mParentDir =
+ CommandHelper.getAbsolutePath(
+ ExplorerApplication.
+ getInstance().getApplicationContext(), src, console);
+ }
+ }
- } catch (Exception e) {
- // Try to resolve from a console
- String abspath =
- CommandHelper.getAbsolutePath(
- ExplorerApplication.getInstance().
- getApplicationContext(), src, console);
- //Resolve the parent directory
- this.mParentDir =
- CommandHelper.getParentDir(
- ExplorerApplication.getInstance().getApplicationContext(),
- abspath, console);
- }
+ /**
+ * Constructor of <code>ListCommand</code>. FileInfo mode
+ *
+ * @param src The file system object to be listed
+ * @param followSymlinks If follow the symlink
+ * @param console The console in which retrieve the parent directory information.
+ * <code>null</code> to attach to the default console
+ * @throws InvalidCommandDefinitionException If the command has an invalid definition
+ * @throws FileNotFoundException If the initial directory not exists
+ * @throws NoSuchFileOrDirectory If the file or directory was not found
+ * @throws IOException If initial directory can't not be checked
+ * @throws ConsoleAllocException If the console can't be allocated
+ * @throws InsufficientPermissionsException If an operation requires elevated permissions
+ * @throws CommandNotFoundException If the command was not found
+ * @throws OperationTimeoutException If the operation exceeded the maximum time of wait
+ * @throws ExecutionException If the operation returns a invalid exit code
+ */
+ public ListCommand(String src, boolean followSymlinks, ShellConsole console)
+ throws InvalidCommandDefinitionException, FileNotFoundException,
+ NoSuchFileOrDirectory, IOException, ConsoleAllocException,
+ InsufficientPermissionsException, CommandNotFoundException,
+ OperationTimeoutException, ExecutionException {
+ //If the mode is listing directory, for avoid problems with symlink,
+ //always append a / to the end of the path (if not exists)
+ super(ID_LS_INFO,
+ new String[]{
+ FileHelper.removeTrailingSlash(
+ followSymlinks ?
+ new File(src).getCanonicalPath() :
+ new File(src).getAbsolutePath())});
+
+ //Initialize files to something distinct of null
+ this.mFiles = new ArrayList<FileSystemObject>();
+ this.mMode = LIST_MODE.FILEINFO;
+ this.mSrc = src;
+
+ //Get the absolute path
+ try {
+ this.mParentDir =
+ FileHelper.removeTrailingSlash(
+ new File(src).getCanonicalFile().getParent());
+
+ } catch (Exception e) {
+ // Try to resolve from a console
+ String abspath =
+ CommandHelper.getAbsolutePath(
+ ExplorerApplication.getInstance().
+ getApplicationContext(), src, console);
+ //Resolve the parent directory
+ this.mParentDir =
+ CommandHelper.getParentDir(
+ ExplorerApplication.getInstance().getApplicationContext(),
+ abspath, console);
}
}
@@ -162,7 +192,16 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
//Parse the line into a FileSystemObject reference
if (!symlinks) {
try {
- this.mFiles.add(ParseHelper.toFileSystemObject(this.mParentDir, szLine));
+ FileSystemObject fso =
+ ParseHelper.toFileSystemObject(this.mParentDir, szLine);
+ if (this.mMode.compareTo(LIST_MODE.FILEINFO) == 0 &&
+ fso instanceof Symlink) {
+ // In some situations, xe when the name has a -> the name is
+ // incorrect resolved, but src name should by fine in this case
+ fso.setName(new File(this.mSrc).getName());
+ // The symlink is not resolved here
+ }
+ this.mFiles.add(fso);
} catch (ParseException pEx) {
throw new ParseException(pEx.getMessage(), line);
}
@@ -202,14 +241,18 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
//Fill the data
for (int i = 0; i < symlinksCount; i++) {
try {
- String parent = new File(absPath[i]).getParent();
- String info = refPath[i];
- FileSystemObject fsoRef =
- ParseHelper.toFileSystemObject(parent, info);
- Symlink symLink =
- ((Symlink)this.mFiles.get(
- this.mFiles.size() - symlinksCount + i));
- symLink.setLinkRef(fsoRef);
+ if (absPath[i] != null && absPath[i].length() > 0) {
+ Symlink symLink =
+ ((Symlink)this.mFiles.get(
+ this.mFiles.size() - symlinksCount + i));
+ String name = new File(absPath[i]).getName();
+ symLink.setName(name);
+ String parent = new File(absPath[i]).getParent();
+ String info = refPath[i];
+ FileSystemObject fsoRef =
+ ParseHelper.toFileSystemObject(parent, info);
+ symLink.setLinkRef(fsoRef);
+ }
} catch (Throwable ex) {
//If parsing the file failed, ignore it and threat as a regular
//file (the destination file not exists or can't be resolved)
diff --git a/src/com/cyanogenmod/explorer/commands/shell/ResolveLinkCommand.java b/src/com/cyanogenmod/explorer/commands/shell/ResolveLinkCommand.java
index 4c131f1e..e2bdb3e7 100644
--- a/src/com/cyanogenmod/explorer/commands/shell/ResolveLinkCommand.java
+++ b/src/com/cyanogenmod/explorer/commands/shell/ResolveLinkCommand.java
@@ -47,7 +47,7 @@ public class ResolveLinkCommand extends SyncResultProgram implements ResolveLink
* @throws InvalidCommandDefinitionException If the command has an invalid definition
*/
public ResolveLinkCommand(String src) throws InvalidCommandDefinitionException {
- super(ID, src, new File(src).getAbsolutePath());
+ super(ID, src, new File(src).getParentFile().getAbsolutePath());
}
/**
diff --git a/src/com/cyanogenmod/explorer/commands/shell/ShellExecutableCreator.java b/src/com/cyanogenmod/explorer/commands/shell/ShellExecutableCreator.java
index b13afb1a..3d455ecf 100644
--- a/src/com/cyanogenmod/explorer/commands/shell/ShellExecutableCreator.java
+++ b/src/com/cyanogenmod/explorer/commands/shell/ShellExecutableCreator.java
@@ -34,7 +34,6 @@ import com.cyanogenmod.explorer.commands.FolderUsageExecutable;
import com.cyanogenmod.explorer.commands.GroupsExecutable;
import com.cyanogenmod.explorer.commands.IdentityExecutable;
import com.cyanogenmod.explorer.commands.ListExecutable;
-import com.cyanogenmod.explorer.commands.ListExecutable.LIST_MODE;
import com.cyanogenmod.explorer.commands.MountExecutable;
import com.cyanogenmod.explorer.commands.MountPointInfoExecutable;
import com.cyanogenmod.explorer.commands.MoveExecutable;
@@ -276,12 +275,25 @@ public class ShellExecutableCreator implements ExecutableCreator {
* {@inheritDoc}
*/
@Override
- public ListExecutable createListExecutable(String src, LIST_MODE mode)
+ public ListExecutable createListExecutable(String src)
throws CommandNotFoundException {
try {
- return new ListCommand(src, mode, this.mConsole);
+ return new ListCommand(src, this.mConsole);
} catch (Throwable throwEx) {
- throw new CommandNotFoundException("ListCommand", throwEx); //$NON-NLS-1$
+ throw new CommandNotFoundException("ListCommand (DIRECTORY)", throwEx); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ListExecutable createFileInfoExecutable(String src, boolean followSymlinks)
+ throws CommandNotFoundException {
+ try {
+ return new ListCommand(src, followSymlinks, this.mConsole);
+ } catch (Throwable throwEx) {
+ throw new CommandNotFoundException("ListCommand (FILEINFO)", throwEx); //$NON-NLS-1$
}
}
diff --git a/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java b/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java
index 5f803826..0d33f15e 100644
--- a/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java
+++ b/src/com/cyanogenmod/explorer/ui/dialogs/FsoPropertiesDialog.java
@@ -245,7 +245,11 @@ public class FsoPropertiesDialog
tvType.setText(MimeTypeHelper.getMimeTypeDescription(this.mContext, this.mFso));
if (this.mFso instanceof Symlink) {
Symlink link = (Symlink)this.mFso;
- tvLink.setText(link.getLinkRef().getFullPath());
+ if (link.getLinkRef() != null) {
+ tvLink.setText(link.getLinkRef().getFullPath());
+ } else {
+ tvLink.setText("-"); //$NON-NLS-1$
+ }
}
vLinkRow.setVisibility(this.mFso instanceof Symlink ? View.VISIBLE : View.GONE);
String size = FileHelper.getHumanReadableSize(this.mFso);
@@ -475,7 +479,8 @@ public class FsoPropertiesDialog
// ensure that the permission was changed
try {
FileSystemObject systemFso =
- CommandHelper.getFileInfo(this.mContext, this.mFso.getFullPath(), null);
+ CommandHelper.getFileInfo(
+ this.mContext, this.mFso.getFullPath(), false, null);
if (systemFso == null || systemFso.getPermissions().compareTo(permissions) != 0) {
// Show the warning message
setMsg(FsoPropertiesDialog.this.mContext.getString(
diff --git a/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java
index f5443d52..3e65e0dd 100644
--- a/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java
+++ b/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java
@@ -490,7 +490,7 @@ public final class ActionsPolicy {
if (onRequestRefreshListener != null) {
FileSystemObject fso = null;
try {
- fso = CommandHelper.getFileInfo(ctx, newName, null);
+ fso = CommandHelper.getFileInfo(ctx, newName, false, null);
} catch (Throwable ex2) {
/**NON BLOCK**/
}
@@ -511,7 +511,7 @@ public final class ActionsPolicy {
FileSystemObject fso = null;
try {
fso =
- CommandHelper.getFileInfo(ctx, newName, null);
+ CommandHelper.getFileInfo(ctx, newName, false, null);
} catch (Throwable ex2) {
/**NON BLOCK**/
}
@@ -739,7 +739,7 @@ public final class ActionsPolicy {
// Check that the operation was completed retrieving the deleted fso
boolean failed = false;
try {
- CommandHelper.getFileInfo(ctx, fso.getFullPath(), null);
+ CommandHelper.getFileInfo(ctx, fso.getFullPath(), false, null);
// Failed. The file still exists
failed = true;
@@ -1071,7 +1071,7 @@ public final class ActionsPolicy {
}
// Check that the operation was completed retrieving the fso modified
- CommandHelper.getFileInfo(ctx, dst.getAbsolutePath(), null);
+ CommandHelper.getFileInfo(ctx, dst.getAbsolutePath(), false, null);
}
};
final BackgroundAsyncTask task = new BackgroundAsyncTask(ctx, callable);
diff --git a/src/com/cyanogenmod/explorer/util/CommandHelper.java b/src/com/cyanogenmod/explorer/util/CommandHelper.java
index 74d2f6b8..f79eb199 100644
--- a/src/com/cyanogenmod/explorer/util/CommandHelper.java
+++ b/src/com/cyanogenmod/explorer/util/CommandHelper.java
@@ -37,7 +37,6 @@ import com.cyanogenmod.explorer.commands.FolderUsageExecutable;
import com.cyanogenmod.explorer.commands.GroupsExecutable;
import com.cyanogenmod.explorer.commands.IdentityExecutable;
import com.cyanogenmod.explorer.commands.ListExecutable;
-import com.cyanogenmod.explorer.commands.ListExecutable.LIST_MODE;
import com.cyanogenmod.explorer.commands.MountExecutable;
import com.cyanogenmod.explorer.commands.MountPointInfoExecutable;
import com.cyanogenmod.explorer.commands.MoveExecutable;
@@ -433,13 +432,44 @@ public final class CommandHelper {
NoSuchFileOrDirectory, InsufficientPermissionsException,
CommandNotFoundException, OperationTimeoutException,
ExecutionException, InvalidCommandDefinitionException {
+ return getFileInfo(context, src, true, console);
+ }
+
+ /**
+ * Method that retrieves the information of a file system object.
+ *
+ * @param context The current context (needed if console == null)
+ * @param src The file system object
+ * @param followSymlinks It should be follow the symlinks
+ * @param console The console in which execute the program. <code>null</code>
+ * to attach to the default console
+ * @return FileSystemObject The file system object reference
+ * @throws FileNotFoundException If the initial directory not exists
+ * @throws IOException If initial directory can't not be checked
+ * @throws InvalidCommandDefinitionException If the command has an invalid definition
+ * @throws NoSuchFileOrDirectory If the file or directory was not found
+ * @throws ConsoleAllocException If the console can't be allocated
+ * @throws InsufficientPermissionsException If an operation requires elevated permissions
+ * @throws CommandNotFoundException If the command was not found
+ * @throws OperationTimeoutException If the operation exceeded the maximum time of wait
+ * @throws ExecutionException If the operation returns a invalid exit code
+ * @see ListExecutable
+ */
+ public static FileSystemObject getFileInfo(
+ Context context, String src, boolean followSymlinks, Console console)
+ throws FileNotFoundException, IOException, ConsoleAllocException,
+ NoSuchFileOrDirectory, InsufficientPermissionsException,
+ CommandNotFoundException, OperationTimeoutException,
+ ExecutionException, InvalidCommandDefinitionException {
Console c = ensureConsole(context, console);
ListExecutable executable =
c.getExecutableFactory().
- newCreator().createListExecutable(src, LIST_MODE.FILEINFO);
+ newCreator().createFileInfoExecutable(src, followSymlinks);
execute(context, executable, c);
List<FileSystemObject> files = executable.getResult();
if (files != null && files.size() > 0) {
+ // Resolve symlinks prior to return the object
+ FileHelper.resolveSymlinks(context, files);
return files.get(0);
}
return null;
@@ -596,9 +626,11 @@ public final class CommandHelper {
Console c = ensureConsole(context, console);
ListExecutable executable =
c.getExecutableFactory().newCreator().
- createListExecutable(directory, LIST_MODE.DIRECTORY);
+ createListExecutable(directory);
execute(context, executable, c);
- return executable.getResult();
+ List<FileSystemObject> result = executable.getResult();
+ FileHelper.resolveSymlinks(context, result);
+ return result;
}
/**
diff --git a/src/com/cyanogenmod/explorer/util/FileHelper.java b/src/com/cyanogenmod/explorer/util/FileHelper.java
index 79782b8e..0011a46b 100644
--- a/src/com/cyanogenmod/explorer/util/FileHelper.java
+++ b/src/com/cyanogenmod/explorer/util/FileHelper.java
@@ -545,9 +545,9 @@ public final class FileHelper {
for (int i = 0; i < cc; i++) {
FileSystemObject fso = files.get(i);
if (fso instanceof Symlink && ((Symlink)fso).getLinkRef() == null) {
- String link = ((Symlink)fso).getLink();
try {
- FileSystemObject symlink = CommandHelper.getFileInfo(context, link, null);
+ FileSystemObject symlink =
+ CommandHelper.resolveSymlink(context, fso.getFullPath(), null);
((Symlink)fso).setLinkRef(symlink);
} catch (Throwable ex) {/**NON BLOCK**/}
}
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/ChangeOwnerCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/ChangeOwnerCommandTest.java
index 6454735d..eb94b804 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/ChangeOwnerCommandTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/ChangeOwnerCommandTest.java
@@ -49,7 +49,7 @@ public class ChangeOwnerCommandTest extends AbstractConsoleTest {
//Create and list the file
CommandHelper.createFile(getContext(), PATH_FILE, getConsole());
FileSystemObject file =
- CommandHelper.getFileInfo(getContext(), PATH_FILE, getConsole());
+ CommandHelper.getFileInfo(getContext(), PATH_FILE, false, getConsole());
//Change the permissions
User oldUser = file.getUser();
@@ -60,7 +60,7 @@ public class ChangeOwnerCommandTest extends AbstractConsoleTest {
assertTrue("response==false", ret); //$NON-NLS-1$
//List the file again
- file = CommandHelper.getFileInfo(getContext(), PATH_FILE, getConsole());
+ file = CommandHelper.getFileInfo(getContext(), PATH_FILE, false, getConsole());
Group lsGroup = file.getGroup();
assertTrue("set group!=list group", //$NON-NLS-1$
newGroup.getName().compareTo(lsGroup.getName()) == 0);
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/ChangePermissionsCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/ChangePermissionsCommandTest.java
index 06309ecc..c9dfe435 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/ChangePermissionsCommandTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/ChangePermissionsCommandTest.java
@@ -47,7 +47,7 @@ public class ChangePermissionsCommandTest extends AbstractConsoleTest {
//Create and list the file
CommandHelper.createFile(getContext(), PATH_FILE, getConsole());
FileSystemObject file =
- CommandHelper.getFileInfo(getContext(), PATH_FILE, getConsole());
+ CommandHelper.getFileInfo(getContext(), PATH_FILE, false, getConsole());
//Change the permissions
Permissions oldpermissions = file.getPermissions();
@@ -60,7 +60,7 @@ public class ChangePermissionsCommandTest extends AbstractConsoleTest {
assertTrue("response==false", ret); //$NON-NLS-1$
//List the files again
- file = CommandHelper.getFileInfo(getContext(), PATH_FILE, getConsole());
+ file = CommandHelper.getFileInfo(getContext(), PATH_FILE, false, getConsole());
Permissions newpermissions = file.getPermissions();
String newOctalPermissions = newpermissions.toOctalString();
assertTrue("newpermissions==oldpermissions", //$NON-NLS-1$
diff --git a/tests/src/com/cyanogenmod/explorer/commands/shell/ListCommandTest.java b/tests/src/com/cyanogenmod/explorer/commands/shell/ListCommandTest.java
index a94555db..79b5aa13 100644
--- a/tests/src/com/cyanogenmod/explorer/commands/shell/ListCommandTest.java
+++ b/tests/src/com/cyanogenmod/explorer/commands/shell/ListCommandTest.java
@@ -18,7 +18,6 @@ package com.cyanogenmod.explorer.commands.shell;
import java.util.List;
-import com.cyanogenmod.explorer.commands.ListExecutable.LIST_MODE;
import com.cyanogenmod.explorer.model.BlockDevice;
import com.cyanogenmod.explorer.model.CharacterDevice;
import com.cyanogenmod.explorer.model.Directory;
@@ -81,7 +80,7 @@ public class ListCommandTest extends AbstractConsoleTest {
* {@link ListCommand#parse(String, String)}
*/
public void testParse() throws Exception {
- ListCommand cmd = new ListCommand(LS_PATH, LIST_MODE.DIRECTORY, getConsole());
+ ListCommand cmd = new ListCommand(LS_PATH, getConsole());
String in =
"drwxr-xr-x root root 2012-05-04 01:51 acct\n" + //$NON-NLS-1$
"-rw-r--r-- root root2 229 2012-05-04 01:51 boot.txt\n" + //$NON-NLS-1$