X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c6a3abf05b4eb41a569fe2ea865f3e0ede6432d9..ac6b3d25ac71cf9bf01bcdb00eb43745af96ffb9:/src/com/owncloud/android/operations/RenameFileOperation.java diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index 58b792ee..fe7ad796 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -80,7 +80,6 @@ public class RenameFileOperation extends RemoteOperation { RemoteOperationResult result = null; LocalMoveMethod move = null; - //MoveMethod move = null; // TODO find out why not use this String newRemotePath = null; try { if (mNewName.equals(mFile.getFileName())) { @@ -94,26 +93,25 @@ public class RenameFileOperation extends RemoteOperation { return new RemoteOperationResult(ResultCode.INVALID_LOCAL_FILE_NAME); } - // check if a remote file with the new name already exists - if (client.existsFile(newRemotePath)) { + // check if a file with the new name already exists + if (client.existsFile(newRemotePath) || // remote check could fail by network failure, or by indeterminate behavior of HEAD for folders ... + mStorageManager.getFileByPath(newRemotePath) != null) { // ... so local check is convenient return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); } - /*move = new MoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()), - client.getBaseUri() + WebdavUtils.encodePath(newRemotePath), - false);*/ move = new LocalMoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()), client.getBaseUri() + WebdavUtils.encodePath(newRemotePath)); int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); if (move.succeeded()) { // create new OCFile instance for the renamed file - OCFile newFile = obtainUpdatedFile(); + /*OCFile newFile = new OCFile(mStorageManager.getFileById(mFile.getParentId()).getRemotePath() + mNewName; // TODO - NOT CREATE NEW OCFILE; ADD setFileName METHOD OCFile oldFile = mFile; - mFile = newFile; + mFile = newFile; */ + mFile.setFileName(mNewName); // try to rename the local copy of the file - if (oldFile.isDown()) { - File f = new File(oldFile.getStoragePath()); + if (mFile.isDown()) { + File f = new File(mFile.getStoragePath()); String newStoragePath = f.getParent() + mNewName; if (f.renameTo(new File(newStoragePath))) { mFile.setStoragePath(newStoragePath); @@ -122,8 +120,20 @@ public class RenameFileOperation extends RemoteOperation { // TODO - study conditions when this could be a problem } - mStorageManager.removeFile(oldFile, false); + //mStorageManager.removeFile(oldFile, false); mStorageManager.saveFile(mFile); + + /* + *} else if (mFile.isDirectory() && (status == 207 || status >= 500)) { + * // TODO + * // if server fails in the rename of a folder, some children files could have been moved to a folder with the new name while some others + * // stayed in the old folder; + * // + * // easiest and heaviest solution is synchronizing the parent folder (or the full account); + * // + * // a better solution is synchronizing the folders with the old and new names; + *} + */ } @@ -152,12 +162,14 @@ public class RenameFileOperation extends RemoteOperation { * IMPORTANT: The test must be made in the same file system where files are download. The internal storage * could be formatted with a different file system. * + * TODO move this method, and maybe FileDownload.get***Path(), to a class with utilities specific for the interactions with the file system + * * @return 'True' if a temporal file named with the name to set could be created in the file system where * local files are stored. */ private boolean isValidNewName() { // check tricky names - if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator)) { + if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) { return false; } // create a test file @@ -178,24 +190,6 @@ public class RenameFileOperation extends RemoteOperation { } - /** - * Creates a new OCFile for the new remote name of the renamed file. - * - * @return OCFile object with the same information than mFile, but the renamed remoteFile and the storagePath (empty) - */ - private OCFile obtainUpdatedFile() { - OCFile file = new OCFile(mStorageManager.getFileById(mFile.getParentId()).getRemotePath() + mNewName); - file.setCreationTimestamp(mFile.getCreationTimestamp()); - file.setFileId(mFile.getFileId()); - file.setFileLength(mFile.getFileLength()); - file.setKeepInSync(mFile.keepInSync()); - file.setLastSyncDate(mFile.getLastSyncDate()); - file.setMimetype(mFile.getMimetype()); - file.setModificationTimestamp(mFile.getModificationTimestamp()); - file.setParentId(mFile.getParentId()); - return file; - } - // move operation - TODO: find out why org.apache.jackrabbit.webdav.client.methods.MoveMethod is not used instead ¿? private class LocalMoveMethod extends DavMethodBase {