Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #46 from owncloud/instant_uploads_set_path
Browse files Browse the repository at this point in the history
Buf fixes: released some stale connections
  • Loading branch information
davivel committed Nov 25, 2014
2 parents 2799b3e + 07daf8c commit 0030d82
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
6 changes: 6 additions & 0 deletions src/com/owncloud/android/lib/common/OwnCloudClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ private int patchRedirection(int status, HttpMethod method) throws HttpException
if (location != null) {
Log_OC.d(TAG + " #" + mInstanceNumber,
"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));
Header destination = method.getRequestHeader("Destination");
if (destination == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,17 @@ public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) {
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
MkColMethod mkcol = null;

boolean noInvalidChars = FileUtils.isValidPath(mRemotePath);
if (noInvalidChars) {
try {
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
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());
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
client.exhaustResponse(mkcol.getResponseBodyAsStream());

} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);

} finally {
if (mkcol != null)
mkcol.releaseConnection();
}
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);
}
Expand All @@ -105,7 +92,28 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}


private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) {
private RemoteOperationResult createFolder(OwnCloudClient client) {
RemoteOperationResult result = null;
MkColMethod mkcol = null;
try {
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
client.exhaustResponse(mkcol.getResponseBodyAsStream());

} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);

} finally {
if (mkcol != null)
mkcol.releaseConnection();
}
return result;
}

private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) {
RemoteOperation operation = new CreateRemoteFolderOperation(parentPath,
mCreateFullPath);
return operation.execute(client);
Expand Down

0 comments on commit 0030d82

Please sign in to comment.