From 9c18fbdcb677deed0ff956782eeb637d0bef3275 Mon Sep 17 00:00:00 2001 From: euxane Date: Wed, 18 Sep 2024 23:41:13 +0200 Subject: paths: rename log -> logs directory --- app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | 8 ++++---- .../main/java/org/pacien/tincapp/context/StorageMigrator.kt | 7 ++++--- .../pacien/tincapp/storageprovider/FilesDocumentsProvider.kt | 10 +++++----- .../main/res/layout/configure_browse_directories_fragment.xml | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt index 1d0879a..c1bb27e 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt @@ -27,7 +27,7 @@ import java.io.FileNotFoundException * @implNote Logs and PID files are stored in the cache directory for automatic collection. */ object AppPaths { - private const val APP_LOG_DIR = "log" + private const val APP_LOGS_DIR = "logs" private const val APP_TINC_RUNTIME_DIR = "run" private const val APP_TINC_NETWORKS_DIR = "networks" @@ -54,7 +54,7 @@ object AppPaths { private fun binDir() = File(context.applicationInfo.nativeLibraryDir) fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR)) - fun logDir() = withDir(File(privateCacheDir(), APP_LOG_DIR)) + fun logsDir() = withDir(File(privateCacheDir(), APP_LOGS_DIR)) fun confDir() = withDir(File(privateFilesDir(), APP_TINC_NETWORKS_DIR)) fun confDir(netName: String) = File(confDir(), netName) @@ -62,9 +62,9 @@ object AppPaths { fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE) fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE) fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE) - fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName)) + fun logFile(netName: String) = File(logsDir(), String.format(LOGFILE_FORMAT, netName)) fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName)) - fun appLogFile() = File(logDir(), APPLOG_FILE) + fun appLogFile() = File(logsDir(), APPLOG_FILE) fun crashFlagFile() = File(privateCacheDir(), CRASHFLAG_FILE) fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } diff --git a/app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt b/app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt index 855827c..6bde2f6 100644 --- a/app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt +++ b/app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt @@ -20,6 +20,7 @@ package org.pacien.tincapp.context import org.pacien.tincapp.extensions.Java.defaultMessage import org.slf4j.LoggerFactory +import java.io.File import java.io.IOException /** @@ -34,7 +35,8 @@ class StorageMigrator { fun migrate() { migrateConfigurationDirectory() - migrateLogDirectory() + migrateLogDirectory(context.externalCacheDir) + migrateLogDirectory(File(context.cacheDir, "log")) // migrated to "logs" } private fun migrateConfigurationDirectory() { @@ -56,8 +58,7 @@ class StorageMigrator { } } - private fun migrateLogDirectory() { - val oldLogDir = context.externalCacheDir + private fun migrateLogDirectory(oldLogDir: File?) { if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do try { diff --git a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt index 80b7331..1e5fd6f 100644 --- a/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt +++ b/app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt @@ -46,7 +46,7 @@ class FilesDocumentsProvider : DocumentsProvider() { private const val ROOT_ID = "" private const val ROOT_DOCUMENT_ID = "/" const val VIRTUAL_ROOT_NETWORKS = "networks" - const val VIRTUAL_ROOT_LOG = "log" + const val VIRTUAL_ROOT_LOGS = "logs" private val DEFAULT_ROOT_PROJECTION = arrayOf( Root.COLUMN_ROOT_ID, @@ -107,7 +107,7 @@ class FilesDocumentsProvider : DocumentsProvider() { when (parentDocumentId) { ROOT_DOCUMENT_ID -> { addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE) - addVirtualDirRow(VIRTUAL_ROOT_LOG, Document.FLAG_DIR_SUPPORTS_CREATE) + addVirtualDirRow(VIRTUAL_ROOT_LOGS, Document.FLAG_DIR_SUPPORTS_CREATE) } else -> fileForDocumentId(parentDocumentId).listFiles()?.forEach { @@ -174,7 +174,7 @@ class FilesDocumentsProvider : DocumentsProvider() { val under = if (it.size >= 2) it[1] else "" when (root) { VIRTUAL_ROOT_NETWORKS -> File(AppPaths.confDir(), under) - VIRTUAL_ROOT_LOG -> File(AppPaths.logDir(), under) + VIRTUAL_ROOT_LOGS -> File(AppPaths.logsDir(), under) else -> throw FileNotFoundException() } } @@ -182,8 +182,8 @@ class FilesDocumentsProvider : DocumentsProvider() { private fun documentIdForFile(file: File): String = if (AppPaths.confDir().isParentOf(file, false)) { File(VIRTUAL_ROOT_NETWORKS, file.pathUnder(AppPaths.confDir())).path - } else if (AppPaths.logDir().isParentOf(file, false)) { - File(VIRTUAL_ROOT_LOG, file.pathUnder(AppPaths.logDir())).path + } else if (AppPaths.logsDir().isParentOf(file, false)) { + File(VIRTUAL_ROOT_LOGS, file.pathUnder(AppPaths.logsDir())).path } else { throw IllegalArgumentException() } diff --git a/app/src/main/res/layout/configure_browse_directories_fragment.xml b/app/src/main/res/layout/configure_browse_directories_fragment.xml index e0fc64a..97b4548 100644 --- a/app/src/main/res/layout/configure_browse_directories_fragment.xml +++ b/app/src/main/res/layout/configure_browse_directories_fragment.xml @@ -45,7 +45,7 @@ + android:onClick="@{() -> openDirectoryTree.invoke(FilesDocumentsProvider.VIRTUAL_ROOT_LOGS)}">