aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt4
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/StorageMigrator.kt11
2 files changed, 9 insertions, 6 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 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 {
51 51
52 private fun privateCacheDir() = context.cacheDir!! 52 private fun privateCacheDir() = context.cacheDir!!
53 private fun publicCacheDir() = context.externalCacheDir!! 53 private fun publicCacheDir() = context.externalCacheDir!!
54 private fun publicFilesDir() = context.getExternalFilesDir(null)
54 private fun binDir() = File(context.applicationInfo.nativeLibraryDir) 55 private fun binDir() = File(context.applicationInfo.nativeLibraryDir)
56
55 fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR)) 57 fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR))
56 fun logDir() = withDir(File(publicCacheDir(), APP_LOG_DIR)) 58 fun logDir() = withDir(File(publicCacheDir(), APP_LOG_DIR))
57 fun confDir() = withDir(File(context.filesDir!!, APP_TINC_NETWORKS_DIR)) 59 fun confDir() = withDir(File(publicFilesDir(), APP_TINC_NETWORKS_DIR))
58 60
59 fun confDir(netName: String) = File(confDir(), netName) 61 fun confDir(netName: String) = File(confDir(), netName)
60 fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR) 62 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
23import java.io.IOException 23import java.io.IOException
24 24
25/** 25/**
26 * Migrates the configuration from the external storage (used before version 0.32) to the internal storage. 26 * Migrates the configuration from the private storage (used before version 0.38) to the
27 * user-accessible storage (through the USB storage mode).
27 * 28 *
28 * @author pacien 29 * @author pacien
29 */ 30 */
30class StorageMigrator { 31class StorageMigrator {
31 private val log by lazy { LoggerFactory.getLogger(this.javaClass)!! } 32 private val log by lazy { LoggerFactory.getLogger(this.javaClass)!! }
32 private val context by lazy { App.getContext() } 33 private val context by lazy { App.getContext() }
33 private val paths = AppPaths
34 34
35 fun migrate() { 35 fun migrate() {
36 migrateConfigurationDirectory() 36 migrateConfigurationDirectory()
@@ -38,17 +38,18 @@ class StorageMigrator {
38 } 38 }
39 39
40 private fun migrateConfigurationDirectory() { 40 private fun migrateConfigurationDirectory() {
41 val oldConfigDir = context.getExternalFilesDir(null) 41 val oldConfigDir = context.filesDir
42 if (oldConfigDir == null || oldConfigDir.listFiles().isNullOrEmpty()) return // nothing to do 42 if (oldConfigDir == null || oldConfigDir.listFiles().isNullOrEmpty()) return // nothing to do
43 43
44 try { 44 try {
45 val newConfigDir = context.getExternalFilesDir(null)!!
45 log.info( 46 log.info(
46 "Migrating files present in old configuration directory at {} to {}", 47 "Migrating files present in old configuration directory at {} to {}",
47 oldConfigDir.absolutePath, 48 oldConfigDir.absolutePath,
48 paths.confDir() 49 newConfigDir.absolutePath
49 ) 50 )
50 51
51 oldConfigDir.copyRecursively(paths.confDir(), overwrite = false) 52 oldConfigDir.copyRecursively(newConfigDir, overwrite = false)
52 oldConfigDir.deleteRecursively() 53 oldConfigDir.deleteRecursively()
53 } catch (e: IOException) { 54 } catch (e: IOException) {
54 log.warn("Could not complete configuration directory migration: {}", e.defaultMessage()) 55 log.warn("Could not complete configuration directory migration: {}", e.defaultMessage())