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.secure;
19 import android.util.Log;
21 import com.cyanogenmod.filemanager.commands.MoveExecutable;
22 import com.cyanogenmod.filemanager.console.ExecutionException;
23 import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
24 import com.cyanogenmod.filemanager.console.secure.SecureConsole;
25 import com.cyanogenmod.filemanager.model.MountPoint;
26 import com.cyanogenmod.filemanager.util.FileHelper;
28 import java.io.IOException;
30 import de.schlichtherle.truezip.file.TFile;
35 * A class for move a file or directory.
37 public class MoveCommand extends Program implements MoveExecutable {
39 private static final String TAG = "MoveCommand"; //$NON-NLS-1$
41 private final String mSrc;
42 private final String mDst;
45 * Constructor of <code>MoveCommand</code>.
47 * @param console The current console
48 * @param src The name of the file or directory to be moved
49 * @param dst The name of the file or directory in which move the source file or directory
51 public MoveCommand(SecureConsole console, String src, String dst) {
61 public boolean requiresSync() {
69 public Boolean getResult() {
77 public void execute() throws NoSuchFileOrDirectory, ExecutionException {
80 String.format("Creating from %s to %s", this.mSrc, this.mDst)); //$NON-NLS-1$
83 TFile s = getConsole().buildRealFile(this.mSrc);
84 TFile d = getConsole().buildRealFile(this.mDst);
87 Log.v(TAG, "Result: FAIL. NoSuchFileOrDirectory"); //$NON-NLS-1$
89 throw new NoSuchFileOrDirectory(this.mSrc);
92 //Move or copy recursively
95 TFile.cp_r(s, d, SecureConsole.DETECTOR, SecureConsole.DETECTOR);
96 } catch (IOException ex) {
97 throw new ExecutionException("Failed to move file or directory", ex);
99 if (!FileHelper.deleteFolder(s)) {
101 Log.v(TAG, "Result: OK. WARNING. Source not deleted."); //$NON-NLS-1$
105 // Use rename. We are not cross filesystem with this console, so this operation
108 TFile.mv(s, d, SecureConsole.DETECTOR);
109 } catch (IOException ex) {
110 // Make sure truecrypt was right
111 // There's a strange bug in it where it thinks that a file did not
112 // move over. However, it actually did.
114 throw new ExecutionException("Failed to rename file or directory", ex);
120 Log.v(TAG, "Result: OK"); //$NON-NLS-1$
128 public MountPoint getSrcWritableMountPoint() {
136 public MountPoint getDstWritableMountPoint() {