From 3ae90ab521a4aa69f394c0490f27e9db6106ce0e Mon Sep 17 00:00:00 2001 From: Julian Raufelder Date: Wed, 7 Jul 2021 16:58:43 +0200 Subject: [PATCH] Fix Dropbox vault unlock in vault version 7 and caching enabled --- .../dropbox/DropboxCloudContentRepository.kt | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/data/src/main/java/org/cryptomator/data/cloud/dropbox/DropboxCloudContentRepository.kt b/data/src/main/java/org/cryptomator/data/cloud/dropbox/DropboxCloudContentRepository.kt index 3a66f108..1d9f39d1 100644 --- a/data/src/main/java/org/cryptomator/data/cloud/dropbox/DropboxCloudContentRepository.kt +++ b/data/src/main/java/org/cryptomator/data/cloud/dropbox/DropboxCloudContentRepository.kt @@ -7,6 +7,7 @@ import com.dropbox.core.NetworkIOException import com.dropbox.core.v2.files.CreateFolderErrorException import com.dropbox.core.v2.files.DeleteErrorException import com.dropbox.core.v2.files.DownloadErrorException +import com.dropbox.core.v2.files.GetMetadataErrorException import com.dropbox.core.v2.files.ListFolderErrorException import com.dropbox.core.v2.files.RelocationErrorException import org.cryptomator.data.cloud.InterceptingCloudContentRepository @@ -157,22 +158,26 @@ internal class DropboxCloudContentRepository(private val cloud: DropboxCloud, co try { cloud.read(file, encryptedTmpFile, data, progressAware) } catch (e: IOException) { - if (ExceptionUtil.contains(e, DownloadErrorException::class.java)) { - if (ExceptionUtil.extract(e, DownloadErrorException::class.java).get().errorValue.pathValue.isNotFound) { - throw NoSuchCloudFileException(file.name) - } - } - throw FatalBackendException(e) + mapToNoSuchCloudFileExceptionIfMatches(e, file)?.let { throw it } ?: throw FatalBackendException(e) } catch (e: DbxException) { - if (ExceptionUtil.contains(e, DownloadErrorException::class.java)) { - if (ExceptionUtil.extract(e, DownloadErrorException::class.java).get().errorValue.pathValue.isNotFound) { - throw NoSuchCloudFileException(file.name) - } - } - throw FatalBackendException(e) + mapToNoSuchCloudFileExceptionIfMatches(e, file)?.let { throw it } ?: throw FatalBackendException(e) } } + private fun mapToNoSuchCloudFileExceptionIfMatches(e: Exception, file: DropboxFile) : NoSuchCloudFileException? { + if (ExceptionUtil.contains(e, GetMetadataErrorException::class.java)) { + if (ExceptionUtil.extract(e, GetMetadataErrorException::class.java).get().errorValue.pathValue.isNotFound) { + return NoSuchCloudFileException(file.name) + } + } + else if (ExceptionUtil.contains(e, DownloadErrorException::class.java)) { + if (ExceptionUtil.extract(e, DownloadErrorException::class.java).get().errorValue.pathValue.isNotFound) { + return NoSuchCloudFileException(file.name) + } + } + return null + } + @Throws(BackendException::class) override fun delete(node: DropboxNode) { try {