Catch the underlying exception when WebDAV writing fails due to closed pipe

This commit is contained in:
Torsten Grote 2024-06-24 11:28:59 -03:00
parent 823eb4ffab
commit 7afd496db9
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -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()