From 539ca3131dadff60f8d1a15aa310cc8d8161b6a9 Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 10 Jun 2021 08:33:15 +0200 Subject: [PATCH] temp Dir for log export --- .../general/maintenance/ImportExportPrefsImpl.kt | 2 +- .../plugins/general/maintenance/MaintenancePlugin.kt | 4 ++-- .../general/maintenance/MaintenancePluginTest.kt | 2 +- .../general/maintenance/PrefFileListProvider.kt | 10 +++++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt index bf83f2c5bc..908d801137 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt @@ -363,7 +363,7 @@ class ImportExportPrefsImpl @Inject constructor( override fun exportUserEntriesCsv(activity: FragmentActivity, singleEntries: Single>) { val entries = singleEntries.blockingGet() prefFileList.ensureExportDirExists() - val newFile = prefFileList.newExportXmlFile() + val newFile = prefFileList.newExportCsvFile() try { classicPrefsFormat.saveCsv(newFile, entries) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt index cf5c9a6621..17de20da13 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePlugin.kt @@ -54,7 +54,7 @@ class MaintenancePlugin @Inject constructor( 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 logs = getLogFiles(amount) - val zipDir = fileListProvider.ensureExportDirExists() + val zipDir = fileListProvider.ensureTempDirExists() val zipFile = File(zipDir, constructName()) aapsLogger.debug("zipFile: ${zipFile.absolutePath}") val zip = zipLogs(zipFile, logs) @@ -81,7 +81,7 @@ class MaintenancePlugin @Inject constructor( file.delete() } } - val exportDir = fileListProvider.ensureExportDirExists() + val exportDir = fileListProvider.ensureTempDirExists() if (exportDir.exists()) { val expFiles = exportDir.listFiles() for (file in expFiles) { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt index c05b26a7a4..0a8dd8db50 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt @@ -38,7 +38,7 @@ class MaintenancePluginTest : TestBase() { sut = MaintenancePlugin(injector, context, resourceHelper, sp, nsSettingsStatus, aapsLogger, buildHelper, ConfigImpl(), fileListProvider, loggerUtils) `when`(loggerUtils.suffix).thenReturn(".log.zip") `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() { diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt index 1aedd1dfcb..028b97ca75 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt @@ -31,6 +31,7 @@ class PrefFileListProvider @Inject constructor( private val path = File(Environment.getExternalStorageDirectory().toString()) private val aapsPath = File(path, "AAPS" + File.separator + "preferences") 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") companion object { @@ -103,6 +104,13 @@ class PrefFileListProvider @Inject constructor( return exportsPath } + fun ensureTempDirExists(): File { + if (!tempPath.exists()) { + tempPath.mkdirs() + } + return tempPath + } + fun ensureExtraDirExists(): File { if (!extraPath.exists()) { extraPath.mkdirs() @@ -115,7 +123,7 @@ class PrefFileListProvider @Inject constructor( return File(aapsPath, timeLocal + "_" + config.FLAVOR + ".json") } - fun newExportXmlFile(): File { + fun newExportCsvFile(): File { val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss")) return File(exportsPath, timeLocal + "_UserEntry.csv") }