diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt index b56bf32c..9fb4d318 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStorage.kt @@ -22,14 +22,12 @@ 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 @@ -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() } /** @@ -233,18 +213,6 @@ 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) - } - } - } - } /**