OSDN Git Service

CMFM: CYAN-533 - Increase timeout in File Manager
[android-x86/packages-apps-CMFileManager.git] / src / com / cyanogenmod / filemanager / commands / shell / CopyCommand.java
1 /*
2  * Copyright (C) 2012 The CyanogenMod Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.cyanogenmod.filemanager.commands.shell;
18
19 import com.cyanogenmod.filemanager.commands.CopyExecutable;
20 import com.cyanogenmod.filemanager.console.CommandNotFoundException;
21 import com.cyanogenmod.filemanager.console.ExecutionException;
22 import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
23 import com.cyanogenmod.filemanager.model.MountPoint;
24 import com.cyanogenmod.filemanager.util.MountPointHelper;
25
26 import java.text.ParseException;
27
28
29 /**
30  * A class for copy a file or directory.
31  *
32  * {@link "http://unixhelp.ed.ac.uk/CGI/man-cgi?cp"}
33  */
34 public class CopyCommand extends SyncResultProgram implements CopyExecutable {
35
36     private static final String ID = "cp";  //$NON-NLS-1$
37     private Boolean mRet;
38     private final String mDst;
39
40     /**
41      * Constructor of <code>CopyCommand</code>.
42      *
43      * @param src The name of the file or directory to be copied
44      * @param dst The name of the file or directory in which copy the source file or directory
45      * @throws InvalidCommandDefinitionException If the command has an invalid definition
46      */
47     public CopyCommand(String src, String dst) throws InvalidCommandDefinitionException {
48         super(ID, src, dst);
49         this.mDst = dst;
50     }
51
52     /**
53      * {@inheritDoc}
54      */
55     @Override
56     public void parse(String in, String err) throws ParseException {
57         //Release the return object
58         this.mRet = Boolean.TRUE;
59     }
60
61     /**
62      * {@inheritDoc}
63      */
64     @Override
65     public Boolean getResult() {
66         return this.mRet;
67     }
68
69     /**
70      * {@inheritDoc}
71      */
72     @Override
73     public void checkExitCode(int exitCode)
74             throws InsufficientPermissionsException, CommandNotFoundException, ExecutionException {
75         if (exitCode != 0) {
76             throw new ExecutionException("exitcode != 0"); //$NON-NLS-1$
77         }
78     }
79
80     /**
81      * {@inheritDoc}
82      */
83     @Override
84     public MountPoint getSrcWritableMountPoint() {
85         return null;
86     }
87
88     /**
89      * {@inheritDoc}
90      */
91     @Override
92     public MountPoint getDstWritableMountPoint() {
93         return MountPointHelper.getMountPointFromDirectory(this.mDst);
94     }
95
96     /**
97      * {@inheritDoc}
98      */
99     @Override
100     public boolean isIndefinitelyWait() {
101         return true;
102     }
103 }