Return actually available RestoreSets

Before, we were always returnign a dummy RestoreSet,
if one was actually available or not.

Now, we also include the device name.
Note that it is planned to store the actual device name
and other metadata in an encrypted file
so that the backup server will not learn it.
This commit is contained in:
Torsten Grote 2019-09-05 17:39:48 -03:00
parent 7a7059cda3
commit aa3aad8fb3
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 13 additions and 6 deletions

View file

@ -46,7 +46,7 @@ internal class RestoreCoordinator(
* or [TRANSPORT_ERROR] (an error occurred, the restore should be aborted and rescheduled).
*/
fun startRestore(token: Long, packages: Array<out PackageInfo>): Int {
if (state != null) throw IllegalStateException()
check(state == null)
Log.i(TAG, "Start restore with ${packages.map { info -> info.packageName }}")
state = RestoreCoordinatorState(token, packages.iterator())
return TRANSPORT_OK

View file

@ -7,19 +7,26 @@ import com.stevesoltys.backup.transport.restore.FullRestorePlugin
import com.stevesoltys.backup.transport.restore.KVRestorePlugin
import com.stevesoltys.backup.transport.restore.RestorePlugin
class DocumentsProviderRestorePlugin(
private val documentsStorage: DocumentsStorage) : RestorePlugin {
class DocumentsProviderRestorePlugin(private val storage: DocumentsStorage) : RestorePlugin {
override val kvRestorePlugin: KVRestorePlugin by lazy {
DocumentsProviderKVRestorePlugin(documentsStorage)
DocumentsProviderKVRestorePlugin(storage)
}
override val fullRestorePlugin: FullRestorePlugin by lazy {
DocumentsProviderFullRestorePlugin(documentsStorage)
DocumentsProviderFullRestorePlugin(storage)
}
override fun getAvailableRestoreSets(): Array<RestoreSet>? {
return arrayOf(RestoreSet("default", "device", DEFAULT_RESTORE_SET_TOKEN))
val rootDir = storage.rootBackupDir ?: return null
val restoreSets = ArrayList<RestoreSet>()
for (file in rootDir.listFiles()) {
if (file.isDirectory && file.findFile(DEFAULT_RESTORE_SET_TOKEN.toString()) != null) {
// TODO include time of last backup
file.name?.let { restoreSets.add(RestoreSet(it, it, DEFAULT_RESTORE_SET_TOKEN)) }
}
}
return restoreSets.toTypedArray()
}
override fun getCurrentRestoreSet(): Long {