Skip to content

Commit

Permalink
Merge pull request #700 from grote/okhttp4.12
Browse files Browse the repository at this point in the history
Upgrade dav4jvm library
  • Loading branch information
grote authored Jun 24, 2024
2 parents cba160b + a1f6be0 commit d571749
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 49 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ dependencies {
* in the top-level `libs` folder to reflect that.
* You can copy these libraries from ~/.gradle/caches/modules-2/files-2.1
*/
// later versions than 2.1.1 require newer kotlin version
implementation(fileTree("${rootProject.rootDir}/libs/koin-android").include("*.jar"))
implementation(fileTree("${rootProject.rootDir}/libs/koin-android").include("*.aar"))

implementation(fileTree("${rootProject.rootDir}/libs").include("kotlin-bip39-jvm-1.0.6.jar"))

// dav4jvm - later versions of okhttp need kotlin > 1.9.0
implementation(fileTree("${rootProject.rootDir}/libs/dav4jvm").include("*.jar"))

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.PropertyRegistry
import at.bitfire.dav4jvm.Response
import at.bitfire.dav4jvm.Response.HrefRelation.SELF
import at.bitfire.dav4jvm.XmlUtils.NS_WEBDAV
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.DisplayName
import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.dav4jvm.property.webdav.DisplayName
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
import at.bitfire.dav4jvm.property.webdav.ResourceType
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.ConnectionSpec
import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.internal.closeQuietly
import okio.BufferedSink
import org.xmlpull.v1.XmlPullParser
import java.io.IOException
Expand Down Expand Up @@ -113,28 +111,10 @@ internal abstract class WebDavStorage(
protected fun getInputStream(location: HttpUrl): InputStream {
val davCollection = DavCollection(okHttpClient, location)

val pipedInputStream = PipedExceptionInputStream()
val pipedOutputStream = PipedOutputStream(pipedInputStream)

GlobalScope.launch(Dispatchers.IO) {
try {
davCollection.get(accept = "", headers = null) { response ->
val inputStream = response.body?.byteStream()
?: throw IOException("No response body")
debugLog { "getInputStream($location) = $response" }
pipedOutputStream.use { outputStream ->
inputStream.copyTo(outputStream)
}
}
} catch (e: Exception) {
debugLog { "Exception while getting input stream: $e" }
// pass exception to stream, so it gets thrown when stream is closed
// if we'd just throw it here, it would be uncaught, on a different thread
pipedInputStream.throwable = e
pipedOutputStream.closeQuietly()
}
}
return pipedInputStream
val response = davCollection.get(accept = "", headers = null)
debugLog { "getInputStream($location) = $response" }
if (response.code / 100 != 2) throw IOException("HTTP error ${response.code}")
return response.body?.byteStream() ?: throw IOException()
}

/**
Expand Down Expand Up @@ -233,22 +213,10 @@ internal abstract class WebDavStorage(
}
}

private class PipedExceptionInputStream : PipedInputStream() {
var throwable: Throwable? = null

override fun close() {
super.close()
throwable?.let { e ->
if (e is IOException) throw e
else throw IOException(e)
}
}
}

}

/**
* A fake version of [at.bitfire.dav4jvm.property.GetLastModified] which we register
* A fake version of [at.bitfire.dav4jvm.property.webdav.GetLastModified] which we register
* so we don't need to depend on `org.apache.commons.lang3` which is used for date parsing.
*/
class GetLastModified : Property {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import at.bitfire.dav4jvm.DavCollection
import at.bitfire.dav4jvm.Response.HrefRelation.SELF
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.exception.NotFoundException
import at.bitfire.dav4jvm.property.DisplayName
import at.bitfire.dav4jvm.property.QuotaAvailableBytes
import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.dav4jvm.property.webdav.DisplayName
import at.bitfire.dav4jvm.property.webdav.QuotaAvailableBytes
import at.bitfire.dav4jvm.property.webdav.ResourceType
import com.stevesoltys.seedvault.plugins.EncryptedMetadata
import com.stevesoltys.seedvault.plugins.StoragePlugin
import com.stevesoltys.seedvault.plugins.chunkFolderRegex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import android.util.Log
import at.bitfire.dav4jvm.DavCollection
import at.bitfire.dav4jvm.Response.HrefRelation.SELF
import at.bitfire.dav4jvm.exception.NotFoundException
import at.bitfire.dav4jvm.property.DisplayName
import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.dav4jvm.property.webdav.DisplayName
import at.bitfire.dav4jvm.property.webdav.ResourceType
import com.stevesoltys.seedvault.crypto.KeyManager
import com.stevesoltys.seedvault.plugins.chunkFolderRegex
import com.stevesoltys.seedvault.plugins.webdav.DIRECTORY_ROOT
Expand Down
4 changes: 2 additions & 2 deletions libs/dav4jvm/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

java_import {
name: "seedvault-lib-dav4jvm",
jars: ["dav4jvm-2.2.1.jar"],
jars: ["dav4jvm-b8be778.jar"],
sdk_version: "current",
}

java_import {
name: "seedvault-lib-okhttp",
jars: ["okhttp-4.11.0.jar"],
jars: ["okhttp-4.12.0.jar"],
sdk_version: "current",
}

Expand Down
Binary file removed libs/dav4jvm/dav4jvm-2.2.1.jar
Binary file not shown.
Binary file added libs/dav4jvm/dav4jvm-b8be778.jar
Binary file not shown.
Binary file removed libs/dav4jvm/okhttp-4.11.0.jar
Binary file not shown.
Binary file added libs/dav4jvm/okhttp-4.12.0.jar
Binary file not shown.

0 comments on commit d571749

Please sign in to comment.