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 cdbbb6f038..90f051f2a1 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 @@ -69,11 +69,24 @@ class MaintenancePlugin @Inject constructor( val files = logDir.listFiles { _: File?, name: String -> (name.startsWith("AndroidAPS") && name.endsWith(".zip")) } + val autotunefiles = logDir.listFiles { _: File?, name: String -> + (name.startsWith("autotune") && name.endsWith(".zip")) + } + val amount = sp.getInt(R.string.key_logshipper_amount, keep) + val keepIndex = amount - 1 + if (autotunefiles != null && autotunefiles.isNotEmpty()) { + Arrays.sort(autotunefiles) { f1: File, f2: File -> f2.name.compareTo(f1.name) } + var delAutotuneFiles = listOf(*autotunefiles) + if (keepIndex < delAutotuneFiles.size) { + delAutotuneFiles = delAutotuneFiles.subList(keepIndex, delAutotuneFiles.size) + for (file in delAutotuneFiles) { + file.delete() + } + } + } if (files == null || files.isEmpty()) return Arrays.sort(files) { f1: File, f2: File -> f2.name.compareTo(f1.name) } var delFiles = listOf(*files) - val amount = sp.getInt(R.string.key_logshipper_amount, keep) - val keepIndex = amount - 1 if (keepIndex < delFiles.size) { delFiles = delFiles.subList(keepIndex, delFiles.size) for (file in delFiles) {