Skip to content

Commit

Permalink
Test quota
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Oct 10, 2023
1 parent 6376984 commit 7c4e01a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Up @@ -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

/**
Expand All @@ -46,14 +47,22 @@ import java.io.IOException
class CheckEnoughQuotaRemoteOperation(val path: String, private val fileSize: Long) :
RemoteOperation<Boolean>() {

@Deprecated("Deprecated in Java")
@Suppress("Detekt.ReturnCount")
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
)
Expand Down Expand Up @@ -82,9 +91,9 @@ class CheckEnoughQuotaRemoteOperation(val path: String, private val fileSize: Lo
}
return RemoteOperationResult(ResultCode.ETAG_CHANGED)
}
private fun isSuccess(quota: Long) : Boolean {
retunr quota >= fileSize ||

private fun isSuccess(quota: Long): Boolean {
return quota >= fileSize ||
quota == UNKNOWN_FREE_SPACE ||
quota == UNCOMPUTED_FREE_SPACE ||
quota == UNLIMITED_FREE_SPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7c4e01a

Please sign in to comment.