FIX OC-2101: App crash when renaming a folder while the server is down or without internet connection

This commit is contained in:
masensio 2013-11-18 12:07:54 +01:00
parent 6e092bf235
commit f780062616
3 changed files with 19 additions and 15 deletions

View file

@ -151,7 +151,7 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName, mOldFolderPath); RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName, mOldFolderPath);
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
result = mActivity.renameFile(mNewFileName, mNewFilePath, mOldFileName, mOldFilePath); result = mActivity.renameFile(mNewFileName + mFileExtension, mNewFilePath + mFileExtension, mOldFileName, mOldFilePath);
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
} }

View file

@ -66,6 +66,11 @@ public class RenameRemoteFileOperation extends RemoteOperation {
return new RemoteOperationResult(ResultCode.OK); return new RemoteOperationResult(ResultCode.OK);
} }
// check if a file with the new name already exists
if (client.existsFile(mNewRemotePath)) {
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
}
move = new LocalMoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mOldRemotePath), move = new LocalMoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mOldRemotePath),
client.getBaseUri() + WebdavUtils.encodePath(mNewRemotePath)); client.getBaseUri() + WebdavUtils.encodePath(mNewRemotePath));
int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);

View file

@ -93,9 +93,8 @@ public class RenameFileOperation extends RemoteOperation {
mNewRemotePath += OCFile.PATH_SEPARATOR; mNewRemotePath += OCFile.PATH_SEPARATOR;
} }
// check if a file with the new name already exists // ckeck local overwrite
if (client.existsFile(mNewRemotePath) || // remote check could fail by network failure. by indeterminate behavior of HEAD for folders ... if (mStorageManager.getFileByPath(mNewRemotePath) != null) {
mStorageManager.getFileByPath(mNewRemotePath) != null) { // ... so local check is convenient
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
} }