From 823eb4ffab71587164814a80b363f110ae4e8071 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 18 Jun 2024 14:04:58 -0300 Subject: [PATCH 1/3] Improve logging relevant for WebDAV streams --- .../seedvault/transport/backup/FullBackup.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt index da10e5178..eed8acab6 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt @@ -20,7 +20,7 @@ import com.stevesoltys.seedvault.plugins.StoragePluginManager import com.stevesoltys.seedvault.plugins.isOutOfSpace import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager -import libcore.io.IoUtils.closeQuietly +import java.io.Closeable import java.io.EOFException import java.io.IOException import java.io.InputStream @@ -210,9 +210,9 @@ internal class FullBackup( val state = this.state ?: throw AssertionError("Trying to clear empty state.") return try { state.outputStream?.flush() - closeQuietly(state.outputStream) - closeQuietly(state.inputStream) - closeQuietly(state.inputFileDescriptor) + closeLogging(state.outputStream) + closeLogging(state.inputStream) + closeLogging(state.inputFileDescriptor) TRANSPORT_OK } catch (e: IOException) { Log.w(TAG, "Error when clearing state", e) @@ -222,4 +222,10 @@ internal class FullBackup( } } + private fun closeLogging(closable: Closeable?) = try { + closable?.close() + } catch (e: Exception) { + Log.w(TAG, "Error closing: ", e) + } + } From 7afd496db977147a2724900ed807ffb21de86e3f Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Mon, 24 Jun 2024 11:28:59 -0300 Subject: [PATCH 2/3] 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 9fb4d318f..faec3f847 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() From 490c7882e46b3342ac53abfabca3979e4f40a4c5 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 27 Jun 2024 17:19:12 -0300 Subject: [PATCH 3/3] Add missing docs for sendBackupData() --- .../seedvault/transport/backup/BackupCoordinator.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt index 4e3b53bb0..510428d44 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt @@ -277,6 +277,16 @@ internal class BackupCoordinator( return full.performFullBackup(targetPackage, fileDescriptor, flags, token, salt) } + /** + * Tells the transport to read [numBytes] bytes of data from the socket file descriptor + * provided in the [performFullBackup] call, and deliver those bytes to the datastore. + * + * @param numBytes The number of bytes of tarball data available to be read from the socket. + * @return [TRANSPORT_OK] on successful processing of the data; [TRANSPORT_ERROR] to + * indicate a fatal error situation. If an error is returned, the system will + * call finishBackup() and stop attempting backups until after a backoff and retry + * interval. + */ suspend fun sendBackupData(numBytes: Int) = full.sendBackupData(numBytes) /**