From c8a882761fc2f03f3207cc2828ee9e2532e02247 Mon Sep 17 00:00:00 2001 From: jabarros Date: Mon, 24 Nov 2014 10:53:05 +0100 Subject: [PATCH 1/2] Fix. If the path does not exist is not created when it hast to create more than 4 folders --- src/com/owncloud/android/lib/common/OwnCloudClient.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 36282af7..d303b857 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -247,6 +247,12 @@ public class OwnCloudClient extends HttpClient { 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) { From 07daf8c58c138210be10d22202f0029b4d30bd08 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 24 Nov 2014 14:13:18 +0100 Subject: [PATCH 2/2] Grant that connections are released per level when a folder with depth > MAX_CONNECTIONS is created with all its ancestors --- .../files/CreateRemoteFolderOperation.java | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java index f0ba3492..7443692e 100644 --- a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java @@ -73,30 +73,17 @@ public class CreateRemoteFolderOperation extends RemoteOperation { @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); } @@ -105,7 +92,28 @@ public class CreateRemoteFolderOperation extends RemoteOperation { } - 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);