diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/backend/saf/SafBackendTest.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/backend/saf/SafBackendTest.kt index 9a2adf88..530eaac1 100644 --- a/app/src/androidTest/java/com/stevesoltys/seedvault/backend/saf/SafBackendTest.kt +++ b/app/src/androidTest/java/com/stevesoltys/seedvault/backend/saf/SafBackendTest.kt @@ -36,4 +36,9 @@ class SafBackendTest : BackendTest(), KoinComponent { fun `test remove create write file`(): Unit = runBlocking { testRemoveCreateWriteFile() } + + @Test + fun `test free space and create app blob without root folder`(): Unit = runBlocking { + testTestFreeSpaceAndCreateBlob() + } } diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt index 5ba281f6..7e9c17c4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt @@ -115,6 +115,7 @@ class AppBackupWorker( Log.e(TAG, "Error while running setForeground: ", e) } val freeSpace = backendManager.getFreeSpace() + Log.i(TAG, "freeSpace: $freeSpace") if (freeSpace != null && freeSpace < MIN_FREE_SPACE) { nm.onInsufficientSpaceError() return Result.failure() diff --git a/core/src/main/java/org/calyxos/seedvault/core/backends/BackendTest.kt b/core/src/main/java/org/calyxos/seedvault/core/backends/BackendTest.kt index 9046160c..c98fe923 100644 --- a/core/src/main/java/org/calyxos/seedvault/core/backends/BackendTest.kt +++ b/core/src/main/java/org/calyxos/seedvault/core/backends/BackendTest.kt @@ -12,6 +12,7 @@ import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertNotNull +import kotlin.test.assertTrue @VisibleForTesting public abstract class BackendTest { @@ -159,4 +160,23 @@ public abstract class BackendTest { } } + protected suspend fun testTestFreeSpaceAndCreateBlob() { + assertTrue(backend.test()) + + // not asserting free space as each backend may have different amounts available + println("Free space: ${backend.getFreeSpace()}") + + val repoId = Random.nextBytes(32).toHexString() + val blob = AppBackupFileType.Blob(repoId, Random.nextBytes(32).toHexString()) + val bytes = Random.nextBytes(2342) + try { + backend.save(blob).use { + it.write(bytes) + } + assertContentEquals(bytes, backend.load(blob as FileHandle).readAllBytes()) + } finally { + backend.remove(blob) + } + } + } diff --git a/core/src/main/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackend.kt b/core/src/main/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackend.kt index b43d97a4..d42fb9b7 100644 --- a/core/src/main/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackend.kt +++ b/core/src/main/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackend.kt @@ -111,7 +111,7 @@ public class WebDavBackend( log.debugLog { "getFreeSpace() = $response" } val quota = response.properties.getOrNull(0) as? QuotaAvailableBytes val availableBytes = quota?.quotaAvailableBytes ?: -1 - if (availableBytes > 0) { + if (availableBytes >= 0) { cont.resume(availableBytes) } else { cont.resume(null) diff --git a/core/src/test/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackendTest.kt b/core/src/test/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackendTest.kt index e4fb4ca7..5a118e47 100644 --- a/core/src/test/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackendTest.kt +++ b/core/src/test/java/org/calyxos/seedvault/core/backends/webdav/WebDavBackendTest.kt @@ -22,4 +22,9 @@ public class WebDavBackendTest : BackendTest() { public fun `test remove, create, write file`(): Unit = runBlocking { testRemoveCreateWriteFile() } + + @Test + public fun `test, free space and create app blob without root folder`(): Unit = runBlocking { + testTestFreeSpaceAndCreateBlob() + } }