From 564e675c0a44dfb3b914d1d4307fdde844ad082f Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 29 Jul 2023 23:32:28 +0200 Subject: storage: move app and tinc daemon logs to user-accessible cache directory --- app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | 11 ++++++----- .../pacien/tincapp/context/ConfigurationDirectoryMigrator.kt | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'app/src/main/java') 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 9aa2037..92348d6 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2020 Pacien TRAN-GIRARD + * Copyright (C) 2017-2023 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,10 +49,11 @@ object AppPaths { private val context by lazy { App.getContext() } - private fun cacheDir() = context.cacheDir!! + private fun privateCacheDir() = context.cacheDir!! + private fun publicCacheDir() = context.externalCacheDir!! private fun binDir() = File(context.applicationInfo.nativeLibraryDir) - fun runtimeDir() = withDir(File(cacheDir(), APP_TINC_RUNTIME_DIR)) - fun logDir() = withDir(File(cacheDir(), APP_LOG_DIR)) + fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR)) + fun logDir() = withDir(File(publicCacheDir(), APP_LOG_DIR)) fun confDir() = withDir(File(context.filesDir!!, APP_TINC_NETWORKS_DIR)) fun confDir(netName: String) = File(confDir(), netName) @@ -63,7 +64,7 @@ object AppPaths { fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName)) fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName)) fun appLogFile() = File(logDir(), APPLOG_FILE) - fun crashFlagFile() = File(cacheDir(), CRASHFLAG_FILE) + fun crashFlagFile() = File(privateCacheDir(), CRASHFLAG_FILE) fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } fun withDir(f: File) = f.apply { if (!exists()) mkdirs() } diff --git a/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt b/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt index 0fedf6f..ea0b7d8 100644 --- a/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt +++ b/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2020 Pacien TRAN-GIRARD + * Copyright (C) 2017-2023 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,7 +56,7 @@ class ConfigurationDirectoryMigrator { } private fun migrateLogDirectory() { - val oldLogDir = context.externalCacheDir + val oldLogDir = context.cacheDir if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do try { -- cgit v1.2.3