From 7af2bef60caa354c03e67ef07a70d194aa177398 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Jul 2023 00:13:22 +0200 Subject: storage/config: move configuration files to the user-accessible storage --- app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | 4 +++- .../main/java/org/pacien/tincapp/context/StorageMigrator.kt | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'app') 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 92348d6..9e69790 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt @@ -51,10 +51,12 @@ object AppPaths { private fun privateCacheDir() = context.cacheDir!! private fun publicCacheDir() = context.externalCacheDir!! + private fun publicFilesDir() = context.getExternalFilesDir(null) private fun binDir() = File(context.applicationInfo.nativeLibraryDir) + 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() = withDir(File(publicFilesDir(), APP_TINC_NETWORKS_DIR)) fun confDir(netName: String) = File(confDir(), netName) fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR) 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 de8009c..e5740b8 100644 --- a/app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt +++ b/app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt @@ -23,14 +23,14 @@ import org.slf4j.LoggerFactory import java.io.IOException /** - * Migrates the configuration from the external storage (used before version 0.32) to the internal storage. + * Migrates the configuration from the private storage (used before version 0.38) to the + * user-accessible storage (through the USB storage mode). * * @author pacien */ class StorageMigrator { private val log by lazy { LoggerFactory.getLogger(this.javaClass)!! } private val context by lazy { App.getContext() } - private val paths = AppPaths fun migrate() { migrateConfigurationDirectory() @@ -38,17 +38,18 @@ class StorageMigrator { } private fun migrateConfigurationDirectory() { - val oldConfigDir = context.getExternalFilesDir(null) + val oldConfigDir = context.filesDir if (oldConfigDir == null || oldConfigDir.listFiles().isNullOrEmpty()) return // nothing to do try { + val newConfigDir = context.getExternalFilesDir(null)!! log.info( "Migrating files present in old configuration directory at {} to {}", oldConfigDir.absolutePath, - paths.confDir() + newConfigDir.absolutePath ) - oldConfigDir.copyRecursively(paths.confDir(), overwrite = false) + oldConfigDir.copyRecursively(newConfigDir, overwrite = false) oldConfigDir.deleteRecursively() } catch (e: IOException) { log.warn("Could not complete configuration directory migration: {}", e.defaultMessage()) -- cgit v1.2.3