aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreuxane2024-09-18 23:41:13 +0200
committereuxane2024-09-18 23:41:13 +0200
commit9c18fbdcb677deed0ff956782eeb637d0bef3275 (patch)
tree0f8bc70635dc299cccedacb5ac809544ace5a466
parent09a608d6a3b0af70dd28a889b2977783b1cf9982 (diff)
downloadtincapp-9c18fbdcb677deed0ff956782eeb637d0bef3275.tar.gz
paths: rename log -> logs directory
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt8
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt7
-rw-r--r--app/src/main/java/org/pacien/tincapp/storageprovider/FilesDocumentsProvider.kt10
-rw-r--r--app/src/main/res/layout/configure_browse_directories_fragment.xml2
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
27 * @implNote Logs and PID files are stored in the cache directory for automatic collection. 27 * @implNote Logs and PID files are stored in the cache directory for automatic collection.
28 */ 28 */
29object AppPaths { 29object AppPaths {
30 private const val APP_LOG_DIR = "log" 30 private const val APP_LOGS_DIR = "logs"
31 private const val APP_TINC_RUNTIME_DIR = "run" 31 private const val APP_TINC_RUNTIME_DIR = "run"
32 private const val APP_TINC_NETWORKS_DIR = "networks" 32 private const val APP_TINC_NETWORKS_DIR = "networks"
33 33
@@ -54,7 +54,7 @@ object AppPaths {
54 private fun binDir() = File(context.applicationInfo.nativeLibraryDir) 54 private fun binDir() = File(context.applicationInfo.nativeLibraryDir)
55 55
56 fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR)) 56 fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR))
57 fun logDir() = withDir(File(privateCacheDir(), APP_LOG_DIR)) 57 fun logsDir() = withDir(File(privateCacheDir(), APP_LOGS_DIR))
58 fun confDir() = withDir(File(privateFilesDir(), APP_TINC_NETWORKS_DIR)) 58 fun confDir() = withDir(File(privateFilesDir(), APP_TINC_NETWORKS_DIR))
59 59
60 fun confDir(netName: String) = File(confDir(), netName) 60 fun confDir(netName: String) = File(confDir(), netName)
@@ -62,9 +62,9 @@ object AppPaths {
62 fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE) 62 fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE)
63 fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE) 63 fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE)
64 fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE) 64 fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE)
65 fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName)) 65 fun logFile(netName: String) = File(logsDir(), String.format(LOGFILE_FORMAT, netName))
66 fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName)) 66 fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName))
67 fun appLogFile() = File(logDir(), APPLOG_FILE) 67 fun appLogFile() = File(logsDir(), APPLOG_FILE)
68 fun crashFlagFile() = File(privateCacheDir(), CRASHFLAG_FILE) 68 fun crashFlagFile() = File(privateCacheDir(), CRASHFLAG_FILE)
69 69
70 fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } 70 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
20 20
21import org.pacien.tincapp.extensions.Java.defaultMessage 21import org.pacien.tincapp.extensions.Java.defaultMessage
22import org.slf4j.LoggerFactory 22import org.slf4j.LoggerFactory
23import java.io.File
23import java.io.IOException 24import java.io.IOException
24 25
25/** 26/**
@@ -34,7 +35,8 @@ class StorageMigrator {
34 35
35 fun migrate() { 36 fun migrate() {
36 migrateConfigurationDirectory() 37 migrateConfigurationDirectory()
37 migrateLogDirectory() 38 migrateLogDirectory(context.externalCacheDir)
39 migrateLogDirectory(File(context.cacheDir, "log")) // migrated to "logs"
38 } 40 }
39 41
40 private fun migrateConfigurationDirectory() { 42 private fun migrateConfigurationDirectory() {
@@ -56,8 +58,7 @@ class StorageMigrator {
56 } 58 }
57 } 59 }
58 60
59 private fun migrateLogDirectory() { 61 private fun migrateLogDirectory(oldLogDir: File?) {
60 val oldLogDir = context.externalCacheDir
61 if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do 62 if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do
62 63
63 try { 64 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() {
46 private const val ROOT_ID = "" 46 private const val ROOT_ID = ""
47 private const val ROOT_DOCUMENT_ID = "/" 47 private const val ROOT_DOCUMENT_ID = "/"
48 const val VIRTUAL_ROOT_NETWORKS = "networks" 48 const val VIRTUAL_ROOT_NETWORKS = "networks"
49 const val VIRTUAL_ROOT_LOG = "log" 49 const val VIRTUAL_ROOT_LOGS = "logs"
50 50
51 private val DEFAULT_ROOT_PROJECTION = arrayOf( 51 private val DEFAULT_ROOT_PROJECTION = arrayOf(
52 Root.COLUMN_ROOT_ID, 52 Root.COLUMN_ROOT_ID,
@@ -107,7 +107,7 @@ class FilesDocumentsProvider : DocumentsProvider() {
107 when (parentDocumentId) { 107 when (parentDocumentId) {
108 ROOT_DOCUMENT_ID -> { 108 ROOT_DOCUMENT_ID -> {
109 addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE) 109 addVirtualDirRow(VIRTUAL_ROOT_NETWORKS, Document.FLAG_DIR_SUPPORTS_CREATE)
110 addVirtualDirRow(VIRTUAL_ROOT_LOG, Document.FLAG_DIR_SUPPORTS_CREATE) 110 addVirtualDirRow(VIRTUAL_ROOT_LOGS, Document.FLAG_DIR_SUPPORTS_CREATE)
111 } 111 }
112 112
113 else -> fileForDocumentId(parentDocumentId).listFiles()?.forEach { 113 else -> fileForDocumentId(parentDocumentId).listFiles()?.forEach {
@@ -174,7 +174,7 @@ class FilesDocumentsProvider : DocumentsProvider() {
174 val under = if (it.size >= 2) it[1] else "" 174 val under = if (it.size >= 2) it[1] else ""
175 when (root) { 175 when (root) {
176 VIRTUAL_ROOT_NETWORKS -> File(AppPaths.confDir(), under) 176 VIRTUAL_ROOT_NETWORKS -> File(AppPaths.confDir(), under)
177 VIRTUAL_ROOT_LOG -> File(AppPaths.logDir(), under) 177 VIRTUAL_ROOT_LOGS -> File(AppPaths.logsDir(), under)
178 else -> throw FileNotFoundException() 178 else -> throw FileNotFoundException()
179 } 179 }
180 } 180 }
@@ -182,8 +182,8 @@ class FilesDocumentsProvider : DocumentsProvider() {
182 private fun documentIdForFile(file: File): String = 182 private fun documentIdForFile(file: File): String =
183 if (AppPaths.confDir().isParentOf(file, false)) { 183 if (AppPaths.confDir().isParentOf(file, false)) {
184 File(VIRTUAL_ROOT_NETWORKS, file.pathUnder(AppPaths.confDir())).path 184 File(VIRTUAL_ROOT_NETWORKS, file.pathUnder(AppPaths.confDir())).path
185 } else if (AppPaths.logDir().isParentOf(file, false)) { 185 } else if (AppPaths.logsDir().isParentOf(file, false)) {
186 File(VIRTUAL_ROOT_LOG, file.pathUnder(AppPaths.logDir())).path 186 File(VIRTUAL_ROOT_LOGS, file.pathUnder(AppPaths.logsDir())).path
187 } else { 187 } else {
188 throw IllegalArgumentException() 188 throw IllegalArgumentException()
189 } 189 }
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 @@
45 45
46 <LinearLayout 46 <LinearLayout
47 style="@style/AppTheme.ListBlock.Clickable" 47 style="@style/AppTheme.ListBlock.Clickable"
48 android:onClick="@{() -> openDirectoryTree.invoke(FilesDocumentsProvider.VIRTUAL_ROOT_LOG)}"> 48 android:onClick="@{() -> openDirectoryTree.invoke(FilesDocumentsProvider.VIRTUAL_ROOT_LOGS)}">
49 49
50 <TextView 50 <TextView
51 style="@style/AppTheme.BlockTitle" 51 style="@style/AppTheme.BlockTitle"