2 * Copyright (C) 2012 The CyanogenMod Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.cyanogenmod.filemanager.commands.java;
19 import android.util.Log;
21 import com.cyanogenmod.filemanager.commands.MoveExecutable;
22 import com.cyanogenmod.filemanager.console.CancelledOperationException;
23 import com.cyanogenmod.filemanager.console.ExecutionException;
24 import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
25 import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
26 import com.cyanogenmod.filemanager.model.MountPoint;
27 import com.cyanogenmod.filemanager.util.FileHelper;
28 import com.cyanogenmod.filemanager.util.MountPointHelper;
34 * A class for move a file or directory.
36 public class MoveCommand extends Program implements MoveExecutable {
38 private static final String TAG = "MoveCommand"; //$NON-NLS-1$
40 private final String mSrc;
41 private final String mDst;
44 * Constructor of <code>MoveCommand</code>.
46 * @param src The name of the file or directory to be moved
47 * @param dst The name of the file or directory in which move the source file or directory
49 public MoveCommand(String src, String dst) {
59 public Boolean getResult() {
68 throws InsufficientPermissionsException, NoSuchFileOrDirectory, ExecutionException,
69 CancelledOperationException {
72 String.format("Creating from %s to %s", this.mSrc, this.mDst)); //$NON-NLS-1$
75 File s = new File(this.mSrc);
76 File d = new File(this.mDst);
79 Log.v(TAG, "Result: FAIL. NoSuchFileOrDirectory"); //$NON-NLS-1$
81 throw new NoSuchFileOrDirectory(this.mSrc);
84 //Move or copy recursively
86 if (!FileHelper.copyRecursive(s, d, this)) {
88 Log.v(TAG, "Result: FAIL. InsufficientPermissionsException"); //$NON-NLS-1$
90 throw new InsufficientPermissionsException();
92 if (!FileHelper.deleteFolder(s)) {
94 Log.v(TAG, "Result: OK. WARNING. Source not deleted."); //$NON-NLS-1$
98 // Move between filesystem is not allow. If rename fails then use copy operation
100 if (!FileHelper.copyRecursive(s, d, this)) {
102 Log.v(TAG, "Result: FAIL. InsufficientPermissionsException"); //$NON-NLS-1$
104 throw new InsufficientPermissionsException();
106 if (!FileHelper.deleteFolder(s)) {
108 Log.v(TAG, "Result: OK. WARNING. Source not deleted."); //$NON-NLS-1$
115 Log.v(TAG, "Result: OK"); //$NON-NLS-1$
123 public MountPoint getSrcWritableMountPoint() {
124 return MountPointHelper.getMountPointFromDirectory(this.mSrc);
131 public MountPoint getDstWritableMountPoint() {
132 return MountPointHelper.getMountPointFromDirectory(this.mDst);