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

Commit 77bf8cde authored by jruesga's avatar jruesga
Browse files

Better resolve of symlinks in list command

parent da61ea1d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 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="ls" commandPath="cd" commandArgs="%1$s &amp;&amp; /system/bin/ls -al %1$s | /system/xbin/grep -v -e '^l' &amp;&amp; echo '>SIMLINKS>' &amp;&amp; /system/bin/ls -al %1$s | { /system/xbin/grep -e '^l' || true; } &amp;&amp; echo '>SIMLINKS_DATA>' &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- &amp;&amp; /system/bin/ls -aF %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- | awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f &amp;&amp; /system/bin/ls -F %1$s | /system/xbin/grep -e '^l' | /system/xbin/cut -d ' ' -f2- | awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | /system/xbin/xargs -r -n1 /system/xbin/readlink -f | awk '{print &quot;\\&quot;&quot;$0&quot;\\&quot;&quot;}' | { /system/xbin/xargs -r /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" />
+53 −9
Original line number Diff line number Diff line
@@ -139,9 +139,15 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {

        //Get the absolute path
        try {
            if (followSymlinks) {
                this.mParentDir =
                        FileHelper.removeTrailingSlash(
                                new File(src).getCanonicalFile().getParent());
            } else {
                this.mParentDir =
                        FileHelper.removeTrailingSlash(
                                new File(src).getAbsoluteFile().getParent());
            }

        } catch (Exception e) {
            // Try to resolve from a console
@@ -216,12 +222,26 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
                        szLine = br.readLine();
                        line++;

                        //The next information is known:  symlinksCount * 2
                        //The next information is known:  symlinksCount * 3
                        String[] name = new String[symlinksCount];
                        String[] absPath = new String[symlinksCount];
                        String[] refPath = new String[symlinksCount];
                        for (int i = 0; i < symlinksCount; i++) {
                            if (szLine == null || szLine.trim().length() == 0) {
                                name[i] = null;
                                szLine = br.readLine();
                                line++;
                                continue;
                            }
                            name[i] = szLine;
                            szLine = br.readLine();
                            line++;
                        }
                        for (int i = 0; i < symlinksCount; i++) {
                            if (szLine == null || szLine.trim().length() == 0) {
                                absPath[i] = null;
                                szLine = br.readLine();
                                line++;
                                continue;
                            }
                            absPath[i] = szLine;
@@ -231,6 +251,8 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
                        for (int i = 0; i < symlinksCount; i++) {
                            if (szLine == null || szLine.trim().length() == 0) {
                                refPath[i] = null;
                                szLine = br.readLine();
                                line++;
                                continue;
                            }
                            refPath[i] = szLine;
@@ -238,6 +260,27 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
                            line++;
                        }

                        //Fill the parent if is null
                        for (int i = 0; i < symlinksCount; i++) {
                            Symlink symLink =
                                    ((Symlink)this.mFiles.get(
                                            this.mFiles.size() - symlinksCount + i));
                            if (symLink.getParent() == null) {
                                symLink.setParent(FileHelper.ROOT_DIRECTORY);
                            }
                        }

                        // Symlink can cause incoherences in the name because "->" string
                        // Now, we have the real name of the symlink
                        for (int i = 0; i < symlinksCount; i++) {
                            if (name[i] != null) {
                                Symlink symLink =
                                        ((Symlink)this.mFiles.get(
                                                this.mFiles.size() - symlinksCount + i));
                                symLink.setName(name[i]);
                            }
                        }

                        //Fill the data
                        for (int i = 0; i < symlinksCount; i++) {
                            try {
@@ -245,12 +288,13 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
                                    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 parentLink = new File(absPath[i]).getParent();
                                    if (parentLink == null) {
                                        parentLink = FileHelper.ROOT_DIRECTORY;
                                    }
                                    String info = refPath[i];
                                    FileSystemObject fsoRef =
                                            ParseHelper.toFileSystemObject(parent, info);
                                            ParseHelper.toFileSystemObject(parentLink, info);
                                    symLink.setLinkRef(fsoRef);
                                }
                            } catch (Throwable ex) {
@@ -264,10 +308,10 @@ public class ListCommand extends SyncResultProgram implements ListExecutable {
                    //Add the symlink
                    try {
                        this.mFiles.add(ParseHelper.toFileSystemObject(this.mParentDir, szLine));
                        symlinksCount++;
                    } catch (ParseException pEx) {
                        throw new ParseException(pEx.getMessage(), line);
                    }
                    symlinksCount++;
                }

                line++;