mirror of
https://github.com/twofas/2fas-android.git
synced 2024-11-22 02:09:58 +01:00
Fix Google Drive wipe files
This commit is contained in:
parent
993a83db02
commit
8f9a980431
@ -3,5 +3,5 @@ package com.twofasapp.data.cloud.googledrive
|
||||
interface GoogleDrive {
|
||||
suspend fun getBackupFile(): GoogleDriveFileResult
|
||||
suspend fun updateBackupFile(backupContent: String): GoogleDriveResult
|
||||
suspend fun deleteBackupFile(): GoogleDriveResult
|
||||
suspend fun deleteBackupFiles(): GoogleDriveResult
|
||||
}
|
@ -118,7 +118,7 @@ internal class GoogleDriveImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteBackupFile(): GoogleDriveResult {
|
||||
override suspend fun deleteBackupFiles(): GoogleDriveResult {
|
||||
return withContext(dispatchers.io) {
|
||||
try {
|
||||
Timber.d("DeleteFile -> Starting...")
|
||||
@ -127,9 +127,12 @@ internal class GoogleDriveImpl(
|
||||
?: return@withContext GoogleDriveResult.Failure(error = GoogleDriveError.CredentialsNotFound)
|
||||
|
||||
val drive = getDrive(credentials)
|
||||
val backupFileId = getFiles(drive)?.firstOrNull { it.name == backupVersions.first() }?.id
|
||||
if (backupFileId.isNullOrBlank().not()) {
|
||||
drive.files().delete(backupFileId).execute()
|
||||
|
||||
getFiles(drive)?.forEach { file ->
|
||||
if (backupVersions.contains(file.name)) {
|
||||
Timber.d("DeleteFile -> ${file.name}")
|
||||
drive.files().delete(file.id).execute()
|
||||
}
|
||||
}
|
||||
|
||||
Timber.d("DeleteFile <- Success")
|
||||
@ -154,12 +157,13 @@ internal class GoogleDriveImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFiles(drive: Drive) =
|
||||
drive.files().list()
|
||||
private fun getFiles(drive: Drive): List<File>? {
|
||||
return drive.files().list()
|
||||
.setSpaces("appDataFolder")
|
||||
.execute()
|
||||
?.files
|
||||
?.sortedByDescending { it.name.replace("2fas-backup-v", "").replace(".json", "").toIntOrNull() }
|
||||
}
|
||||
|
||||
private fun getDrive(accountCredentials: AccountCredentials): Drive {
|
||||
val googleAccountCredential = GoogleAccountCredential
|
||||
|
@ -17,7 +17,7 @@ class WipeGoogleDriveWork(
|
||||
private val googleAuth: GoogleAuth by inject()
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
googleDrive.deleteBackupFile()
|
||||
googleDrive.deleteBackupFiles()
|
||||
googleAuth.revokeAccess()
|
||||
|
||||
return Result.success()
|
||||
|
Loading…
Reference in New Issue
Block a user