aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt33
1 files changed, 20 insertions, 13 deletions
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 6ea914c..0fedf6f 100644
--- a/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt
@@ -18,9 +18,9 @@
18 18
19package org.pacien.tincapp.context 19package org.pacien.tincapp.context
20 20
21import org.apache.commons.io.FileExistsException 21import org.pacien.tincapp.extensions.Java.defaultMessage
22import org.apache.commons.io.FileUtils
23import org.slf4j.LoggerFactory 22import org.slf4j.LoggerFactory
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 external storage (used before version 0.32) to the internal storage.
@@ -41,14 +41,17 @@ class ConfigurationDirectoryMigrator {
41 val oldConfigDir = context.getExternalFilesDir(null) 41 val oldConfigDir = context.getExternalFilesDir(null)
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 log.info("Configuration files present in old configuration directory at {}.", oldConfigDir.absolutePath) 44 try {
45 for (oldConfig in oldConfigDir.listFiles() ?: emptyArray()) { 45 log.info(
46 try { 46 "Migrating files present in old configuration directory at {} to {}",
47 log.info("Migrating {} to {}", oldConfig.absolutePath, paths.confDir()) 47 oldConfigDir.absolutePath,
48 FileUtils.moveToDirectory(oldConfig, paths.confDir(), true) 48 paths.confDir()
49 } catch (e: FileExistsException) { 49 )
50 log.warn("Could not migrate {}: target already exists.", oldConfig.absolutePath) 50
51 } 51 oldConfigDir.copyRecursively(paths.confDir(), overwrite = false)
52 oldConfigDir.deleteRecursively()
53 } catch (e: IOException) {
54 log.warn("Could not complete configuration directory migration: {}", e.defaultMessage())
52 } 55 }
53 } 56 }
54 57
@@ -56,8 +59,12 @@ class ConfigurationDirectoryMigrator {
56 val oldLogDir = context.externalCacheDir 59 val oldLogDir = context.externalCacheDir
57 if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do 60 if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do
58 61
59 // There's no point moving the log files. Let's delete those instead. 62 try {
60 log.info("Clearing old cache directory at {}", oldLogDir.absolutePath) 63 // There's no point moving the log files. Let's delete those instead.
61 FileUtils.cleanDirectory(oldLogDir) 64 log.info("Clearing old cache directory at {}", oldLogDir.absolutePath)
65 oldLogDir.deleteRecursively()
66 } catch (e: IOException) {
67 log.warn("Could not remove old cache directory: {}", e.defaultMessage())
68 }
62 } 69 }
63} 70}