Allow backups with zero tasks

pull/1136/head
Alex Baker 5 years ago
parent 6c248be43a
commit a0b02c7e9c

@ -74,24 +74,22 @@ class TasksJsonExporter @Inject constructor(
try { try {
val filename = getFileName(exportType) val filename = getFileName(exportType)
val tasks = taskDao.getAll() val tasks = taskDao.getAll()
if (tasks.isNotEmpty()) { val file = File(String.format("%s/%s", context!!.filesDir, BackupConstants.INTERNAL_BACKUP))
val file = File(String.format("%s/%s", context!!.filesDir, BackupConstants.INTERNAL_BACKUP)) file.delete()
file.delete() file.createNewFile()
file.createNewFile() val internalStorageBackup = Uri.fromFile(file)
val internalStorageBackup = Uri.fromFile(file) val os = context!!.contentResolver.openOutputStream(internalStorageBackup)
val os = context!!.contentResolver.openOutputStream(internalStorageBackup) doTasksExport(os, tasks)
doTasksExport(os, tasks) os!!.close()
os!!.close() val externalStorageBackup = FileHelper.newFile(
val externalStorageBackup = FileHelper.newFile( context!!,
context!!, preferences.backupDirectory!!,
preferences.backupDirectory!!, MIME,
MIME, Files.getNameWithoutExtension(filename),
Files.getNameWithoutExtension(filename), EXTENSION)
EXTENSION) FileHelper.copyStream(context!!, internalStorageBackup, externalStorageBackup)
FileHelper.copyStream(context!!, internalStorageBackup, externalStorageBackup) workManager.scheduleDriveUpload(externalStorageBackup, exportType == ExportType.EXPORT_TYPE_SERVICE)
workManager.scheduleDriveUpload(externalStorageBackup, exportType == ExportType.EXPORT_TYPE_SERVICE) BackupManager(context).dataChanged()
BackupManager(context).dataChanged()
}
if (exportType == ExportType.EXPORT_TYPE_MANUAL) { if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
onFinishExport(filename) onFinishExport(filename)
} }

Loading…
Cancel
Save