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:
parent
7a7059cda3
commit
aa3aad8fb3
2 changed files with 13 additions and 6 deletions
|
@ -46,7 +46,7 @@ internal class RestoreCoordinator(
|
||||||
* or [TRANSPORT_ERROR] (an error occurred, the restore should be aborted and rescheduled).
|
* or [TRANSPORT_ERROR] (an error occurred, the restore should be aborted and rescheduled).
|
||||||
*/
|
*/
|
||||||
fun startRestore(token: Long, packages: Array<out PackageInfo>): Int {
|
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 }}")
|
Log.i(TAG, "Start restore with ${packages.map { info -> info.packageName }}")
|
||||||
state = RestoreCoordinatorState(token, packages.iterator())
|
state = RestoreCoordinatorState(token, packages.iterator())
|
||||||
return TRANSPORT_OK
|
return TRANSPORT_OK
|
||||||
|
|
|
@ -7,19 +7,26 @@ import com.stevesoltys.backup.transport.restore.FullRestorePlugin
|
||||||
import com.stevesoltys.backup.transport.restore.KVRestorePlugin
|
import com.stevesoltys.backup.transport.restore.KVRestorePlugin
|
||||||
import com.stevesoltys.backup.transport.restore.RestorePlugin
|
import com.stevesoltys.backup.transport.restore.RestorePlugin
|
||||||
|
|
||||||
class DocumentsProviderRestorePlugin(
|
class DocumentsProviderRestorePlugin(private val storage: DocumentsStorage) : RestorePlugin {
|
||||||
private val documentsStorage: DocumentsStorage) : RestorePlugin {
|
|
||||||
|
|
||||||
override val kvRestorePlugin: KVRestorePlugin by lazy {
|
override val kvRestorePlugin: KVRestorePlugin by lazy {
|
||||||
DocumentsProviderKVRestorePlugin(documentsStorage)
|
DocumentsProviderKVRestorePlugin(storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val fullRestorePlugin: FullRestorePlugin by lazy {
|
override val fullRestorePlugin: FullRestorePlugin by lazy {
|
||||||
DocumentsProviderFullRestorePlugin(documentsStorage)
|
DocumentsProviderFullRestorePlugin(storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAvailableRestoreSets(): Array<RestoreSet>? {
|
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 {
|
override fun getCurrentRestoreSet(): Long {
|
||||||
|
|
Loading…
Reference in a new issue