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

Commit c0a0acd8 authored by jruesga's avatar jruesga
Browse files

New command: LinkCommand (for create symlinks)

parent 26374b90
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@
  <command commandId="folderusage" commandPath="/system/bin/ls" commandArgs="-alR %1$s" />
  <command commandId="folderusage" commandPath="/system/bin/ls" commandArgs="-alR %1$s" />
  <command commandId="groups" commandPath="/system/xbin/groups" commandArgs="" />
  <command commandId="groups" commandPath="/system/xbin/groups" commandArgs="" />
  <command commandId="id" commandPath="/system/bin/id" commandArgs="-Gn" />
  <command commandId="id" commandPath="/system/bin/id" commandArgs="-Gn" />
  <command commandId="link" commandPath="/system/bin/ln" commandArgs="-s %1$s %2$s" />
  <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="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="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="mount" commandPath="/system/bin/mount" commandArgs="-o %1$s,remount -t auto %2$s %3$s" />
+11 −0
Original line number Original line Diff line number Diff line
@@ -200,6 +200,17 @@ public interface ExecutableCreator {
     */
     */
    IdentityExecutable createIdentityExecutable() throws CommandNotFoundException;
    IdentityExecutable createIdentityExecutable() throws CommandNotFoundException;


    /**
     * Method that creates a symlink of an other file system object.
     *
     * @param src The absolute path to the source fso
     * @param link The absolute path to the link fso
     * @return LinkExecutable A {@link LinkExecutable} executable implementation reference
     * @throws CommandNotFoundException If the executable can't be created
     */
    LinkExecutable createLinkExecutable(
            String src, String link) throws CommandNotFoundException;

    /**
    /**
     * Method that creates an executable for list files of a directory.
     * Method that creates an executable for list files of a directory.
     *
     *
+29 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2012 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.explorer.commands;

/**
 * An interface that represents an executable for create symlinks to other file system objects.
 */
public interface LinkExecutable extends WritableExecutable {

    /**
     * {@inheritDoc}
     */
    @Override
    Boolean getResult();
}
+88 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2012 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.explorer.commands.shell;

import com.cyanogenmod.explorer.commands.LinkExecutable;
import com.cyanogenmod.explorer.console.CommandNotFoundException;
import com.cyanogenmod.explorer.console.ExecutionException;
import com.cyanogenmod.explorer.console.InsufficientPermissionsException;
import com.cyanogenmod.explorer.model.MountPoint;
import com.cyanogenmod.explorer.util.MountPointHelper;

import java.text.ParseException;


/**
 * A class for create a symlink of an other file system object.
 *
 * {@link "http://unixhelp.ed.ac.uk/CGI/man-cgi?ln"}
 */
public class LinkCommand extends SyncResultProgram implements LinkExecutable {

    private static final String ID = "link";  //$NON-NLS-1$
    private Boolean mRet;
    private final String mLink;

    /**
     * Constructor of <code>LinkCommand</code>.
     *
     * @param src The path of the source file
     * @param link The path of the link file
     * @throws InvalidCommandDefinitionException If the command has an invalid definition
     */
    public LinkCommand(String src, String link) throws InvalidCommandDefinitionException {
        super(ID, src, link);
        this.mLink = link;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void parse(String in, String err) throws ParseException {
        //Release the return object
        this.mRet = Boolean.TRUE;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Boolean getResult() {
        return this.mRet;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void checkExitCode(int exitCode)
            throws InsufficientPermissionsException, CommandNotFoundException, ExecutionException {
        // Not raise insufficient permissions if the link is in  
        if (exitCode != 0) {
            throw new ExecutionException("exitcode != 0"); //$NON-NLS-1$
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public MountPoint getWritableMountPoint() {
        return MountPointHelper.getMountPointFromDirectory(this.mLink);
    }
}
+15 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import com.cyanogenmod.explorer.commands.FindExecutable;
import com.cyanogenmod.explorer.commands.FolderUsageExecutable;
import com.cyanogenmod.explorer.commands.FolderUsageExecutable;
import com.cyanogenmod.explorer.commands.GroupsExecutable;
import com.cyanogenmod.explorer.commands.GroupsExecutable;
import com.cyanogenmod.explorer.commands.IdentityExecutable;
import com.cyanogenmod.explorer.commands.IdentityExecutable;
import com.cyanogenmod.explorer.commands.LinkExecutable;
import com.cyanogenmod.explorer.commands.ListExecutable;
import com.cyanogenmod.explorer.commands.ListExecutable;
import com.cyanogenmod.explorer.commands.MountExecutable;
import com.cyanogenmod.explorer.commands.MountExecutable;
import com.cyanogenmod.explorer.commands.MountPointInfoExecutable;
import com.cyanogenmod.explorer.commands.MountPointInfoExecutable;
@@ -271,6 +272,20 @@ public class ShellExecutableCreator implements ExecutableCreator {
        }
        }
    }
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public LinkExecutable createLinkExecutable(String src, String link)
            throws CommandNotFoundException {
        try {
            return new LinkCommand(src, link);
        } catch (InvalidCommandDefinitionException icdEx) {
            throw new CommandNotFoundException("LinkCommand", icdEx); //$NON-NLS-1$
        }
    }


    /**
    /**
     * {@inheritDoc}
     * {@inheritDoc}
     */
     */
Loading