temp Dir for log export
This commit is contained in:
parent
8e4067a1ed
commit
539ca3131d
4 changed files with 13 additions and 5 deletions
|
@ -363,7 +363,7 @@ class ImportExportPrefsImpl @Inject constructor(
|
||||||
override fun exportUserEntriesCsv(activity: FragmentActivity, singleEntries: Single<List<UserEntry>>) {
|
override fun exportUserEntriesCsv(activity: FragmentActivity, singleEntries: Single<List<UserEntry>>) {
|
||||||
val entries = singleEntries.blockingGet()
|
val entries = singleEntries.blockingGet()
|
||||||
prefFileList.ensureExportDirExists()
|
prefFileList.ensureExportDirExists()
|
||||||
val newFile = prefFileList.newExportXmlFile()
|
val newFile = prefFileList.newExportCsvFile()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
classicPrefsFormat.saveCsv(newFile, entries)
|
classicPrefsFormat.saveCsv(newFile, entries)
|
||||||
|
|
|
@ -54,7 +54,7 @@ class MaintenancePlugin @Inject constructor(
|
||||||
val recipient = sp.getString(R.string.key_maintenance_logs_email, "logs@androidaps.org")
|
val recipient = sp.getString(R.string.key_maintenance_logs_email, "logs@androidaps.org")
|
||||||
val amount = sp.getInt(R.string.key_maintenance_logs_amount, 2)
|
val amount = sp.getInt(R.string.key_maintenance_logs_amount, 2)
|
||||||
val logs = getLogFiles(amount)
|
val logs = getLogFiles(amount)
|
||||||
val zipDir = fileListProvider.ensureExportDirExists()
|
val zipDir = fileListProvider.ensureTempDirExists()
|
||||||
val zipFile = File(zipDir, constructName())
|
val zipFile = File(zipDir, constructName())
|
||||||
aapsLogger.debug("zipFile: ${zipFile.absolutePath}")
|
aapsLogger.debug("zipFile: ${zipFile.absolutePath}")
|
||||||
val zip = zipLogs(zipFile, logs)
|
val zip = zipLogs(zipFile, logs)
|
||||||
|
@ -81,7 +81,7 @@ class MaintenancePlugin @Inject constructor(
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val exportDir = fileListProvider.ensureExportDirExists()
|
val exportDir = fileListProvider.ensureTempDirExists()
|
||||||
if (exportDir.exists()) {
|
if (exportDir.exists()) {
|
||||||
val expFiles = exportDir.listFiles()
|
val expFiles = exportDir.listFiles()
|
||||||
for (file in expFiles) {
|
for (file in expFiles) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ class MaintenancePluginTest : TestBase() {
|
||||||
sut = MaintenancePlugin(injector, context, resourceHelper, sp, nsSettingsStatus, aapsLogger, buildHelper, ConfigImpl(), fileListProvider, loggerUtils)
|
sut = MaintenancePlugin(injector, context, resourceHelper, sp, nsSettingsStatus, aapsLogger, buildHelper, ConfigImpl(), fileListProvider, loggerUtils)
|
||||||
`when`(loggerUtils.suffix).thenReturn(".log.zip")
|
`when`(loggerUtils.suffix).thenReturn(".log.zip")
|
||||||
`when`(loggerUtils.logDirectory).thenReturn("src/test/res/logger")
|
`when`(loggerUtils.logDirectory).thenReturn("src/test/res/logger")
|
||||||
`when`(fileListProvider.ensureExportDirExists()).thenReturn(File("src/test/res/logger"))
|
`when`(fileListProvider.ensureTempDirExists()).thenReturn(File("src/test/res/logger"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun logFilesTest() {
|
@Test fun logFilesTest() {
|
||||||
|
|
|
@ -31,6 +31,7 @@ class PrefFileListProvider @Inject constructor(
|
||||||
private val path = File(Environment.getExternalStorageDirectory().toString())
|
private val path = File(Environment.getExternalStorageDirectory().toString())
|
||||||
private val aapsPath = File(path, "AAPS" + File.separator + "preferences")
|
private val aapsPath = File(path, "AAPS" + File.separator + "preferences")
|
||||||
private val exportsPath = File(path, "AAPS" + File.separator + "exports")
|
private val exportsPath = File(path, "AAPS" + File.separator + "exports")
|
||||||
|
private val tempPath = File(path, "AAPS" + File.separator + "temp")
|
||||||
private val extraPath = File(path, "AAPS" + File.separator + "extra")
|
private val extraPath = File(path, "AAPS" + File.separator + "extra")
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -103,6 +104,13 @@ class PrefFileListProvider @Inject constructor(
|
||||||
return exportsPath
|
return exportsPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ensureTempDirExists(): File {
|
||||||
|
if (!tempPath.exists()) {
|
||||||
|
tempPath.mkdirs()
|
||||||
|
}
|
||||||
|
return tempPath
|
||||||
|
}
|
||||||
|
|
||||||
fun ensureExtraDirExists(): File {
|
fun ensureExtraDirExists(): File {
|
||||||
if (!extraPath.exists()) {
|
if (!extraPath.exists()) {
|
||||||
extraPath.mkdirs()
|
extraPath.mkdirs()
|
||||||
|
@ -115,7 +123,7 @@ class PrefFileListProvider @Inject constructor(
|
||||||
return File(aapsPath, timeLocal + "_" + config.FLAVOR + ".json")
|
return File(aapsPath, timeLocal + "_" + config.FLAVOR + ".json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun newExportXmlFile(): File {
|
fun newExportCsvFile(): File {
|
||||||
val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss"))
|
val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss"))
|
||||||
return File(exportsPath, timeLocal + "_UserEntry.csv")
|
return File(exportsPath, timeLocal + "_UserEntry.csv")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue