Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nextcloud/android-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0daf61a6fbbbe2365f87191df50eb22b9e46be62
Choose a base ref
..
head repository: nextcloud/android-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7c4e01a66ef664bee55820cef7f144664fc84882
Choose a head ref
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ package com.owncloud.android.lib.resources.files

import android.os.Build
import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.common.OwnCloudBasicCredentials
import com.owncloud.android.lib.common.OwnCloudClientFactory
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
import com.owncloud.android.lib.common.utils.Log_OC
@@ -103,6 +104,7 @@ class UploadFileRemoteOperationIT : AbstractIT() {
// user3 has quota of 1Mb
val client3 = OwnCloudClientFactory.createOwnCloudClient(url, context, true)
client3.credentials = OwnCloudBasicCredentials("user3", "user3")
client3.userId = "user3"

// create file
val filePath = createFile("quota", LARGE_FILE)
@@ -144,6 +146,6 @@ class UploadFileRemoteOperationIT : AbstractIT() {

companion object {
const val TIME_OFFSET = 10
const val LARGE_FILE = 5 * 1024 * 1024L
const val LARGE_FILE = 10 * 1024
}
}
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ import org.apache.jackrabbit.webdav.DavException
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
import org.apache.jackrabbit.webdav.property.DavPropertyName
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet
import java.io.File
import java.io.IOException

/**
@@ -51,10 +52,17 @@ class CheckEnoughQuotaRemoteOperation(val path: String, private val fileSize: Lo
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
var propfind: PropFindMethod? = null
try {
val file = File(path)
val folder = if (file.path.endsWith(FileUtils.PATH_SEPARATOR)) {
file.path
} else {
file.parent ?: throw IllegalStateException("Parent path not found")
}

val propSet = DavPropertyNameSet()
propSet.add(QUOTA_PROPERTY)
propfind = PropFindMethod(
client.getFilesDavUri(path),
client.getFilesDavUri(folder),
propSet,
0
)
@@ -83,8 +91,8 @@ class CheckEnoughQuotaRemoteOperation(val path: String, private val fileSize: Lo
}
return RemoteOperationResult(ResultCode.ETAG_CHANGED)
}
private fun isSuccess(quota: Long) : Boolean {

private fun isSuccess(quota: Long): Boolean {
return quota >= fileSize ||
quota == UNKNOWN_FREE_SPACE ||
quota == UNCOMPUTED_FREE_SPACE ||
Original file line number Diff line number Diff line change
@@ -152,6 +152,17 @@ public UploadFileRemoteOperation(String localPath,
@Override
protected RemoteOperationResult<String> run(OwnCloudClient client) {
RemoteOperationResult<String> result;

// check quota
long fileLength = new File(localPath).length();
RemoteOperationResult checkEnoughQuotaResult =
new CheckEnoughQuotaRemoteOperation(remotePath, fileLength)
.run(client);

if (!checkEnoughQuotaResult.isSuccess()) {
return new RemoteOperationResult<>(checkEnoughQuotaResult.getCode());
}

DefaultHttpMethodRetryHandler oldRetryHandler =
(DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER);