Skip to content

Commit 7c4e01a

Browse files
Test quota
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent 6376984 commit 7c4e01a

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

library/src/androidTest/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperationIT.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package com.owncloud.android.lib.resources.files
2323

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

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

145147
companion object {
146148
const val TIME_OFFSET = 10
147-
const val LARGE_FILE = 5 * 1024 * 1024L
149+
const val LARGE_FILE = 10 * 1024
148150
}
149151
}

library/src/main/java/com/owncloud/android/lib/resources/files/CheckEnoughQuotaRemoteOperation.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import org.apache.jackrabbit.webdav.DavException
3737
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
3838
import org.apache.jackrabbit.webdav.property.DavPropertyName
3939
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet
40+
import java.io.File
4041
import java.io.IOException
4142

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

50+
@Deprecated("Deprecated in Java")
4951
@Suppress("Detekt.ReturnCount")
5052
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
5153
var propfind: PropFindMethod? = null
5254
try {
55+
val file = File(path)
56+
val folder = if (file.path.endsWith(FileUtils.PATH_SEPARATOR)) {
57+
file.path
58+
} else {
59+
file.parent ?: throw IllegalStateException("Parent path not found")
60+
}
61+
5362
val propSet = DavPropertyNameSet()
5463
propSet.add(QUOTA_PROPERTY)
5564
propfind = PropFindMethod(
56-
client.getFilesDavUri(path),
65+
client.getFilesDavUri(folder),
5766
propSet,
5867
0
5968
)
@@ -82,9 +91,9 @@ class CheckEnoughQuotaRemoteOperation(val path: String, private val fileSize: Lo
8291
}
8392
return RemoteOperationResult(ResultCode.ETAG_CHANGED)
8493
}
85-
86-
private fun isSuccess(quota: Long) : Boolean {
87-
retunr quota >= fileSize ||
94+
95+
private fun isSuccess(quota: Long): Boolean {
96+
return quota >= fileSize ||
8897
quota == UNKNOWN_FREE_SPACE ||
8998
quota == UNCOMPUTED_FREE_SPACE ||
9099
quota == UNLIMITED_FREE_SPACE

library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ public UploadFileRemoteOperation(String localPath,
152152
@Override
153153
protected RemoteOperationResult<String> run(OwnCloudClient client) {
154154
RemoteOperationResult<String> result;
155+
156+
// check quota
157+
long fileLength = new File(localPath).length();
158+
RemoteOperationResult checkEnoughQuotaResult =
159+
new CheckEnoughQuotaRemoteOperation(remotePath, fileLength)
160+
.run(client);
161+
162+
if (!checkEnoughQuotaResult.isSuccess()) {
163+
return new RemoteOperationResult<>(checkEnoughQuotaResult.getCode());
164+
}
165+
155166
DefaultHttpMethodRetryHandler oldRetryHandler =
156167
(DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER);
157168

0 commit comments

Comments
 (0)