From 7afd496db977147a2724900ed807ffb21de86e3f Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Mon, 24 Jun 2024 11:28:59 -0300 Subject: [PATCH] Catch the underlying exception when WebDAV writing fails due to closed pipe --- .../seedvault/plugins/webdav/WebDavStorage.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 9fb4d318..faec3f84 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 @@ -197,6 +197,32 @@ internal abstract class WebDavStorage( private var onClose: (() -> Unit)? = null + override fun write(b: Int) { + try { + super.write(b) + } catch (e: Exception) { + try { + onClose?.invoke() + } catch (closeException: Exception) { + e.addSuppressed(closeException) + } + throw e + } + } + + override fun write(b: ByteArray?, off: Int, len: Int) { + try { + super.write(b, off, len) + } catch (e: Exception) { + try { + onClose?.invoke() + } catch (closeException: Exception) { + e.addSuppressed(closeException) + } + throw e + } + } + @Throws(IOException::class) override fun close() { super.close()