From 56e26083fca5e943fe17a0c139adac1c966ef322 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 13 Jun 2024 15:40:28 -0300 Subject: [PATCH] Fix PROPFIND fallback for lighttpd as well --- .../seedvault/plugins/webdav/WebDavStorage.kt | 14 +++++++++++++- .../plugins/webdav/WebDavStoragePlugin.kt | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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 314a7d25..1793320c 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 @@ -142,7 +142,7 @@ internal abstract class WebDavStorage( callback = callback, ) } catch (e: HttpException) { - if (e.code == 400) { + if (e.isUnsupportedPropfind()) { Log.i(TAG, "Got ${e.response}, trying two depth=1 PROPFINDs...") propfindFakeTwo(callback) } else { @@ -169,6 +169,18 @@ internal abstract class WebDavStorage( } } + protected fun HttpException.isUnsupportedPropfind(): Boolean { + // nginx returns 400 for depth=2 + if (code == 400) { + return true + } + // lighttpd returns 403 with error as if we used infinity + if (code == 403 && responseBody?.contains("propfind-finite-depth") == true) { + return true + } + return false + } + protected suspend fun DavCollection.createFolder(xmlBody: String? = null): okhttp3.Response { return try { suspendCoroutine { cont -> diff --git a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt index e2de1e63..8bd9c972 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/plugins/webdav/WebDavStoragePlugin.kt @@ -192,7 +192,7 @@ internal class WebDavStoragePlugin( } } } catch (e: HttpException) { - if (e.code == 400) getBackupTokenWithDepthOne(davCollection, tokens) + if (e.isUnsupportedPropfind()) getBackupTokenWithDepthOne(davCollection, tokens) else throw e } val tokenIterator = tokens.iterator()