|
@@ -24,6 +24,7 @@ import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
|
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.lib.resources.files.RenameRemoteFileOperation;
|
|
import com.owncloud.android.operations.common.SyncOperation;
|
|
import com.owncloud.android.operations.common.SyncOperation;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
@@ -45,6 +46,7 @@ public class MoveFileOperation extends SyncOperation {
|
|
private Account mAccount;
|
|
private Account mAccount;
|
|
private String mNewParentPath;
|
|
private String mNewParentPath;
|
|
private OCFile mFile;
|
|
private OCFile mFile;
|
|
|
|
+ private String mNewPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -59,7 +61,9 @@ public class MoveFileOperation extends SyncOperation {
|
|
mPath = path;
|
|
mPath = path;
|
|
mNewParentPath = newParentPath;
|
|
mNewParentPath = newParentPath;
|
|
mAccount = account;
|
|
mAccount = account;
|
|
|
|
+
|
|
mFile = null;
|
|
mFile = null;
|
|
|
|
+ mNewPath = "";
|
|
}
|
|
}
|
|
|
|
|
|
public OCFile getFile() {
|
|
public OCFile getFile() {
|
|
@@ -75,46 +79,59 @@ public class MoveFileOperation extends SyncOperation {
|
|
@Override
|
|
@Override
|
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
|
RemoteOperationResult result = null;
|
|
RemoteOperationResult result = null;
|
|
|
|
+
|
|
|
|
|
|
mFile = getStorageManager().getFileByPath(mPath);
|
|
mFile = getStorageManager().getFileByPath(mPath);
|
|
|
|
|
|
- // check if the new name is valid in the local file system
|
|
|
|
try {
|
|
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(
|
|
MoveRemoteFileOperation operation = new MoveRemoteFileOperation(
|
|
mFile.getRemotePath(),
|
|
mFile.getRemotePath(),
|
|
mNewPath,
|
|
mNewPath,
|
|
- mFile.isFolder()
|
|
|
|
|
|
+ false
|
|
);
|
|
);
|
|
result = operation.execute(client);
|
|
result = operation.execute(client);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /// 3. local move
|
|
if (result.isSuccess()) {
|
|
if (result.isSuccess()) {
|
|
|
|
+ //moveLocaly();
|
|
|
|
+ /*
|
|
if (mFile.isFolder()) {
|
|
if (mFile.isFolder()) {
|
|
saveLocalDirectory();
|
|
saveLocalDirectory();
|
|
|
|
|
|
} else {
|
|
} else {
|
|
saveLocalFile();
|
|
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) {
|
|
} catch (IOException e) {
|
|
Log_OC.e(TAG, "Move " + mFile.getRemotePath() + " to " +
|
|
Log_OC.e(TAG, "Move " + mFile.getRemotePath() + " to " +
|
|
(mNewParentPath==null) + ": " +
|
|
(mNewParentPath==null) + ": " +
|
|
- ((result!= null) ? result.getLogMessage() : ""), e);
|
|
|
|
|
|
+ ((result!= null) ? result.getLogMessage() : ""), e);*/
|
|
|
|
+ } finally {
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
return result;
|
|
return result;
|
|
@@ -122,25 +139,26 @@ public class MoveFileOperation extends SyncOperation {
|
|
|
|
|
|
|
|
|
|
private void saveLocalDirectory() {
|
|
private void saveLocalDirectory() {
|
|
- getStorageManager().moveFolder(mFile, mNewParentPath);
|
|
|
|
|
|
+ getStorageManager().moveFolder(mFile, mNewPath);
|
|
String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
|
|
String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
|
|
File localDir = new File(localPath);
|
|
File localDir = new File(localPath);
|
|
if (localDir.exists()) {
|
|
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
|
|
// TODO - if renameTo fails, children files that are already down will result unlinked
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void saveLocalFile() {
|
|
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()) {
|
|
if (mFile.isDown()) {
|
|
File f = new File(mFile.getStoragePath());
|
|
File f = new File(mFile.getStoragePath());
|
|
String parentStoragePath = f.getParent();
|
|
String parentStoragePath = f.getParent();
|
|
if (!parentStoragePath.endsWith(File.separator))
|
|
if (!parentStoragePath.endsWith(File.separator))
|
|
parentStoragePath += File.separator;
|
|
parentStoragePath += File.separator;
|
|
- if (f.renameTo(new File(parentStoragePath + mNewName))) {
|
|
|
|
|
|
+ if (f.renameTo(new File())) {
|
|
mFile.setStoragePath(parentStoragePath + mNewName);
|
|
mFile.setStoragePath(parentStoragePath + mNewName);
|
|
}
|
|
}
|
|
// else - NOTHING: the link to the local file is kept although the local name can't be updated
|
|
// else - NOTHING: the link to the local file is kept although the local name can't be updated
|
|
@@ -148,6 +166,7 @@ public class MoveFileOperation extends SyncOperation {
|
|
}
|
|
}
|
|
|
|
|
|
getStorageManager().saveFile(mFile);
|
|
getStorageManager().saveFile(mFile);
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -166,6 +185,9 @@ public class MoveFileOperation extends SyncOperation {
|
|
* @throws IOException When the temporal folder can not be created.
|
|
* @throws IOException When the temporal folder can not be created.
|
|
*/
|
|
*/
|
|
private boolean isValidNewName() throws IOException {
|
|
private boolean isValidNewName() throws IOException {
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ /*
|
|
// check tricky names
|
|
// check tricky names
|
|
if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) {
|
|
if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) {
|
|
return false;
|
|
return false;
|
|
@@ -190,6 +212,7 @@ public class MoveFileOperation extends SyncOperation {
|
|
testFile.delete();
|
|
testFile.delete();
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|