diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 642586c8..f21c9d18 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -35,7 +35,6 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; import com.owncloud.android.lib.common.network.RedirectionPath; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; @@ -58,7 +57,8 @@ import java.io.InputStream; public class OwnCloudClient extends HttpClient { public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; - public static final String NEW_WEBDAV_PATH_4_0 = "/remote.php/dav/files/"; + public static final String NEW_WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/"; + public static final String NEW_WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/files/"; public static final String STATUS_PATH = "/status.php"; public static final String FILES_WEB_PATH = "/index.php/apps/files"; @@ -284,7 +284,8 @@ public class OwnCloudClient extends HttpClient { int status; do { - method.setFollowRedirects(mFollowRedirects); + //TODO Dav4Android doesn't allow follow redirections right now +// method.setFollowRedirects(mFollowRedirects); status = method.execute(); repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter); if (repeatWithFreshCredentials) { @@ -293,8 +294,6 @@ public class OwnCloudClient extends HttpClient { } while (repeatWithFreshCredentials); return status; - - } private void checkFirstRedirection(HttpMethod method) { @@ -422,14 +421,20 @@ public class OwnCloudClient extends HttpClient { } } - public Uri getWebdavUri() { + public Uri getOldFilesWebdavUri() { return Uri.parse(mBaseUri + WEBDAV_PATH_4_0); } - public Uri getNewWebDavUri() { + public Uri getNewFilesWebDavUri() { return mCredentials instanceof OwnCloudAnonymousCredentials - ? Uri.parse(mBaseUri + NEW_WEBDAV_PATH_4_0) - : Uri.parse(mBaseUri + NEW_WEBDAV_PATH_4_0 + mCredentials.getUsername()); + ? Uri.parse(mBaseUri + NEW_WEBDAV_FILES_PATH_4_0) + : Uri.parse(mBaseUri + NEW_WEBDAV_FILES_PATH_4_0 + mCredentials.getUsername()); + } + + public Uri getNewUploadsWebDavUri() { + return mCredentials instanceof OwnCloudAnonymousCredentials + ? Uri.parse(mBaseUri + NEW_WEBDAV_UPLOADS_PATH_4_0) + : Uri.parse(mBaseUri + NEW_WEBDAV_UPLOADS_PATH_4_0 + mCredentials.getUsername()); } /** diff --git a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java index a93ad141..4b2df189 100644 --- a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -28,7 +28,6 @@ package com.owncloud.android.lib.common.accounts; import java.io.IOException; import org.apache.commons.httpclient.Cookie; -import org.apache.commons.httpclient.HttpStatus; import android.accounts.Account; import android.accounts.AccountManager; @@ -38,12 +37,9 @@ import android.accounts.OperationCanceledException; import android.content.Context; import android.net.Uri; -import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; @@ -239,7 +235,7 @@ public class AccountUtils { // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); - Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri(); + Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getOldFilesWebdavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index 373d1bb1..4ba4dedf 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -65,19 +65,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation FileChannel channel = null; RandomAccessFile raf = null; - //MKCOL - try { - MkColMethod mkcol = new MkColMethod( - HttpUtils.stringUrlToHttpUrl(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)) - ); - - String a = ""; - } catch (Exception e) { - - String b = ""; - } - - //TODO // try { // File file = new File(mLocalPath); @@ -90,7 +77,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation // } // // long offset = 0; -// String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + +// String uriPrefix = client.getOldWebdavUri() + WebdavUtils.encodePath(mRemotePath) + // "-chunking-" + Math.abs((new Random()).nextInt(9000) + 1000) + "-"; // long totalLength = file.length(); // long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE); @@ -154,5 +141,4 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation // } return result; } - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java index 6ee51d38..2138b226 100644 --- a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java @@ -104,8 +104,8 @@ public class CopyRemoteFileOperation extends RemoteOperation { RemoteOperationResult result = null; try { CopyMethod copyMethod = new CopyMethod( - HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath)), - client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), + HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)), + client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath), mOverwrite); copyMethod.setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS); diff --git a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java index 214afb92..80763d4e 100644 --- a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java @@ -25,6 +25,8 @@ package com.owncloud.android.lib.resources.files; +import android.net.Uri; + import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.methods.webdav.MkColMethod; @@ -53,20 +55,20 @@ public class CreateRemoteFolderOperation extends RemoteOperation { private static final int READ_TIMEOUT = 30000; private static final int CONNECTION_TIMEOUT = 5000; - - protected String mRemotePath; - protected boolean mCreateFullPath; + private String mRemotePath; + private boolean mCreateFullPath; + private boolean mFolderToSaveChunks; /** * Constructor - * - * @param remotePath Full path to the new directory to create in the remote server. - * @param createFullPath 'True' means that all the ancestor folders should be created - * if don't exist yet. + * @param remotePath Full path to the new directory to create in the remote server. + * @param createFullPath 'True' means that all the ancestor folders should be created. + * @param folderToSaveChunks 'True' means that the folder to create is to save upload chunks. */ - public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) { + public CreateRemoteFolderOperation(String remotePath, boolean createFullPath, boolean folderToSaveChunks) { mRemotePath = remotePath; mCreateFullPath = createFullPath; + mFolderToSaveChunks = folderToSaveChunks; } /** @@ -102,8 +104,8 @@ public class CreateRemoteFolderOperation extends RemoteOperation { private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result; try { - final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(client.getWebdavUri() - + WebdavUtils.encodePath(mRemotePath))); + Uri webDavUri = mFolderToSaveChunks ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri(); + final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(webDavUri + WebdavUtils.encodePath(mRemotePath))); mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS); mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS); final int status = client.executeHttpMethod(mkcol); @@ -124,7 +126,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation { private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, - mCreateFullPath); + mCreateFullPath, mFolderToSaveChunks); return operation.execute(client); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index e3a62d75..057281cd 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -37,7 +37,6 @@ import com.owncloud.android.lib.common.utils.Log_OC; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -103,7 +102,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { RemoteOperationResult result; int status; boolean savedFile = false; - mGet = new GetMethod(HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath))); + mGet = new GetMethod(HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath))); Iterator it; FileOutputStream fos = null; diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index cbce3612..cc6da844 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -88,7 +88,7 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { // client.setFollowRedirects(false); PropfindMethod propfindMethod = new PropfindMethod( - HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mPath)), + HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mPath)), 0, DavUtils.getAllPropset()); @@ -115,14 +115,14 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { ? new RemoteOperationResult(OK) : new RemoteOperationResult(propfindMethod); - Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + + Log_OC.d(TAG, "Existence check for " + client.getOldFilesWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : "")); } catch (Exception e) { result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Existence check for " + client.getWebdavUri() + + Log_OC.e(TAG, "Existence check for " + client.getOldFilesWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException()); diff --git a/src/com/owncloud/android/lib/resources/files/FileUtils.java b/src/com/owncloud/android/lib/resources/files/FileUtils.java index 4edda969..2bca03b4 100644 --- a/src/com/owncloud/android/lib/resources/files/FileUtils.java +++ b/src/com/owncloud/android/lib/resources/files/FileUtils.java @@ -35,7 +35,6 @@ public class FileUtils { public static final String PATH_SEPARATOR = "/"; - public static String getParentPath(String remotePath) { String parentPath = new File(remotePath).getParent(); parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR; @@ -82,5 +81,4 @@ public class FileUtils { } return result; } - -} +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java index 26cdee54..180830ae 100644 --- a/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java @@ -109,8 +109,8 @@ public class MoveRemoteFileOperation extends RemoteOperation { RemoteOperationResult result = null; try { final MoveMethod move = new MoveMethod( - HttpUrl.parse( client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath)), - client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), + HttpUrl.parse( client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)), + client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath), mOverwrite); move.setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS); diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index 31ca2055..437118b5 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -79,7 +79,7 @@ public class ReadRemoteFileOperation extends RemoteOperation { try { // remote request propfind = new PropfindMethod( - HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)), + HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), DEPTH_0, DavUtils.getAllPropset()); diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index 09cfe23e..4d2a22f7 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -75,7 +75,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation { try { PropfindMethod propfindMethod = new PropfindMethod( - HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)), + HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), DavConstants.DEPTH_1, DavUtils.getAllPropset()); diff --git a/src/com/owncloud/android/lib/resources/files/RemoteFile.java b/src/com/owncloud/android/lib/resources/files/RemoteFile.java index bbb5159c..9c49c6c3 100644 --- a/src/com/owncloud/android/lib/resources/files/RemoteFile.java +++ b/src/com/owncloud/android/lib/resources/files/RemoteFile.java @@ -48,7 +48,7 @@ import at.bitfire.dav4android.property.owncloud.OCPrivatelink; import at.bitfire.dav4android.property.owncloud.OCSize; import okhttp3.HttpUrl; -import static com.owncloud.android.lib.common.OwnCloudClient.NEW_WEBDAV_PATH_4_0; +import static com.owncloud.android.lib.common.OwnCloudClient.NEW_WEBDAV_FILES_PATH_4_0; /** * Contains the data of a Remote File from a WebDavEntry @@ -232,7 +232,7 @@ public class RemoteFile implements Parcelable, Serializable { private static String getRemotePathFromUrl(HttpUrl url, String displayName) { - final String pathToRemove = NEW_WEBDAV_PATH_4_0 + displayName; + final String pathToRemove = NEW_WEBDAV_FILES_PATH_4_0 + displayName; return Uri.decode(url.encodedPath()).replace(pathToRemove, ""); } diff --git a/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java index 3afb0761..24a47688 100644 --- a/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java @@ -66,7 +66,7 @@ public class RemoveRemoteFileOperation extends RemoteOperation { try { DeleteMethod deleteMethod = new DeleteMethod( - HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)) + HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)) ); int status = client.executeHttpMethod(deleteMethod); diff --git a/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index d6599dd9..ab1605a1 100644 --- a/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java @@ -106,9 +106,9 @@ public class RenameRemoteFileOperation extends RemoteOperation { return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); } - final MoveMethod move = new MoveMethod(HttpUrl.parse(client.getWebdavUri() + + final MoveMethod move = new MoveMethod(HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mOldRemotePath)), - client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath), false); + client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false); move.setReadTimeout(RENAME_READ_TIMEOUT, TimeUnit.SECONDS); move.setConnectionTimeout(RENAME_READ_TIMEOUT, TimeUnit.SECONDS); diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 3fbd1119..012bea79 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -89,7 +89,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { try { mPutMethod = new PutMethod( - HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath))); + HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath))); mPutMethod.setRetryOnConnectionFailure(false); diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java index 9cdb9e1c..5dc16804 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java @@ -89,7 +89,7 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { try { PropfindMethod propfindMethod = new PropfindMethod( - HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)), + HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)), DEPTH_0, DavUtils.getQuotaPropSet() );