1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Merge pull request #46 from owncloud/instant_uploads_set_path

Buf fixes: released some stale connections
This commit is contained in:
David A. Velasco 2014-11-25 14:08:20 +01:00
commit 0030d82ee8
2 changed files with 37 additions and 23 deletions

View File

@ -247,6 +247,12 @@ public class OwnCloudClient extends HttpClient {
if (location != null) { if (location != null) {
Log_OC.d(TAG + " #" + mInstanceNumber, Log_OC.d(TAG + " #" + mInstanceNumber,
"Location to redirect: " + location.getValue()); "Location to redirect: " + location.getValue());
// Release the connection to avoid reach the max number of connections per host
// due to it will be set a different url
exhaustResponse(method.getResponseBodyAsStream());
method.releaseConnection();
method.setURI(new URI(location.getValue(), true)); method.setURI(new URI(location.getValue(), true));
Header destination = method.getRequestHeader("Destination"); Header destination = method.getRequestHeader("Destination");
if (destination == null) { if (destination == null) {

View File

@ -73,18 +73,31 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
@Override @Override
protected RemoteOperationResult run(OwnCloudClient client) { protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null; RemoteOperationResult result = null;
MkColMethod mkcol = null;
boolean noInvalidChars = FileUtils.isValidPath(mRemotePath); boolean noInvalidChars = FileUtils.isValidPath(mRemotePath);
if (noInvalidChars) { if (noInvalidChars) {
result = createFolder(client);
if (!result.isSuccess() && mCreateFullPath &&
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
if (result.isSuccess()) {
result = createFolder(client); // second (and last) try
}
}
} else {
result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
}
return result;
}
private RemoteOperationResult createFolder(OwnCloudClient client) {
RemoteOperationResult result = null;
MkColMethod mkcol = null;
try { try {
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) {
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try
}
result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders()); result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
client.exhaustResponse(mkcol.getResponseBodyAsStream()); client.exhaustResponse(mkcol.getResponseBodyAsStream());
@ -97,14 +110,9 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
if (mkcol != null) if (mkcol != null)
mkcol.releaseConnection(); mkcol.releaseConnection();
} }
} else {
result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
}
return result; return result;
} }
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) {
RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, RemoteOperation operation = new CreateRemoteFolderOperation(parentPath,
mCreateFullPath); mCreateFullPath);