import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.utils.FileStorageUtils;
private Account mAccount;
private String mNewParentPath;
private OCFile mFile;
+ private String mNewPath;
mPath = path;
mNewParentPath = newParentPath;
mAccount = account;
+
mFile = null;
+ mNewPath = "";
}
public OCFile getFile() {
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
+
mFile = getStorageManager().getFileByPath(mPath);
- // check if the new name is valid in the local file system
try {
- String parentPath = (new File(mFile.getRemotePath())).getParent();
- parentPath = (parentPath.endsWith(OCFile.PATH_SEPARATOR))
- ? parentPath
- : parentPath + OCFile.PATH_SEPARATOR;
+ /// 1. check move validity
- String mNewPath = mNewParentPath + mFile.getFileName();
- if (mFile.isFolder() && !mNewPath.endsWith(OCFile.PATH_SEPARATOR)) {
- mNewPath += OCFile.PATH_SEPARATOR;
- }
-
- // check local overwrite
- if (getStorageManager().getFileByPath(mPath) != null) {
- return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
- }
+ /// 2. remove move
MoveRemoteFileOperation operation = new MoveRemoteFileOperation(
mFile.getRemotePath(),
mNewPath,
- mFile.isFolder()
+ false
);
result = operation.execute(client);
+
+ /// 3. local move
if (result.isSuccess()) {
+ //moveLocaly();
+ /*
if (mFile.isFolder()) {
saveLocalDirectory();
} else {
saveLocalFile();
}
+ */
+ }
+
+
+ String parentPath = (new File(mFile.getRemotePath())).getParent();
+ parentPath = (parentPath.endsWith(OCFile.PATH_SEPARATOR))
+ ? parentPath
+ : parentPath + OCFile.PATH_SEPARATOR;
+
+ mNewPath = mNewParentPath + mFile.getFileName();
+ if (mFile.isFolder() && !mNewPath.endsWith(OCFile.PATH_SEPARATOR)) {
+ mNewPath += OCFile.PATH_SEPARATOR;
+ }
+
+ // check local overwrite
+ if (getStorageManager().getFileByPath(mPath) != null) {
+ return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
}
+ /*
} catch (IOException e) {
Log_OC.e(TAG, "Move " + mFile.getRemotePath() + " to " +
(mNewParentPath==null) + ": " +
- ((result!= null) ? result.getLogMessage() : ""), e);
+ ((result!= null) ? result.getLogMessage() : ""), e);*/
+ } finally {
+
}
return result;
private void saveLocalDirectory() {
- getStorageManager().moveFolder(mFile, mNewParentPath);
+ getStorageManager().moveFolder(mFile, mNewPath);
String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
File localDir = new File(localPath);
if (localDir.exists()) {
- localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewParentPath));
+ localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewPath));
// TODO - if renameTo fails, children files that are already down will result unlinked
}
}
private void saveLocalFile() {
- mFile.setFileName(mNewName);
+ /*
+ mFile.setRFileName(mNewName); <<< NO >
- // try to rename the local copy of the file
+ // try to move the local copy of the file
if (mFile.isDown()) {
File f = new File(mFile.getStoragePath());
String parentStoragePath = f.getParent();
if (!parentStoragePath.endsWith(File.separator))
parentStoragePath += File.separator;
- if (f.renameTo(new File(parentStoragePath + mNewName))) {
+ if (f.renameTo(new File())) {
mFile.setStoragePath(parentStoragePath + mNewName);
}
// else - NOTHING: the link to the local file is kept although the local name can't be updated
}
getStorageManager().saveFile(mFile);
+ */
}
/**
* @throws IOException When the temporal folder can not be created.
*/
private boolean isValidNewName() throws IOException {
+
+ return true;
+ /*
// check tricky names
if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) {
return false;
testFile.delete();
return result;
+ */
}
}
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.owncloud.android.R;
+import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
if (v == mCancelBtn) {
finish();
} else if (v == mChooseBtn) {
- // TODO request to move, OR save selected folder as a result and let request for caller
- Toast.makeText( MoveActivity.this,
- "TODO: MOVE IMPLEMENTATION",
- Toast.LENGTH_LONG)
- .show();
- finish();
+ ComponentsGetter cg = (ComponentsGetter)getSherlockActivity();
+ FileDataStorageManager storageManager = cg.getStorageManager();
+ if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
+ cg.getFileOperationsHelper().removeFile(mTargetFile, false);
+ }
+ cg.getFileOperationsHelper.moveFile(m)
}
}