aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt
diff options
context:
space:
mode:
authorpacien2023-07-29 23:36:12 +0200
committerpacien2023-07-30 03:53:20 +0200
commitf541e7a7d71aac02098157fa53e927884e940f26 (patch)
tree558c7f669a9a2fae9e0c52d43e15c777adb33441 /app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt
parent564e675c0a44dfb3b914d1d4307fdde844ad082f (diff)
downloadtincapp-f541e7a7d71aac02098157fa53e927884e940f26.tar.gz
storage: rename ConfigurationDirectoryMigrator -> StorageMigrator
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt70
1 files changed, 0 insertions, 70 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
deleted file mode 100644
index ea0b7d8..0000000
--- a/app/src/main/java/org/pacien/tincapp/context/ConfigurationDirectoryMigrator.kt
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2023 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.context
20
21import org.pacien.tincapp.extensions.Java.defaultMessage
22import org.slf4j.LoggerFactory
23import java.io.IOException
24
25/**
26 * Migrates the configuration from the external storage (used before version 0.32) to the internal storage.
27 *
28 * @author pacien
29 */
30class ConfigurationDirectoryMigrator {
31 private val log by lazy { LoggerFactory.getLogger(this.javaClass)!! }
32 private val context by lazy { App.getContext() }
33 private val paths = AppPaths
34
35 fun migrate() {
36 migrateConfigurationDirectory()
37 migrateLogDirectory()
38 }
39
40 private fun migrateConfigurationDirectory() {
41 val oldConfigDir = context.getExternalFilesDir(null)
42 if (oldConfigDir == null || oldConfigDir.listFiles().isNullOrEmpty()) return // nothing to do
43
44 try {
45 log.info(
46 "Migrating files present in old configuration directory at {} to {}",
47 oldConfigDir.absolutePath,
48 paths.confDir()
49 )
50
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())
55 }
56 }
57
58 private fun migrateLogDirectory() {
59 val oldLogDir = context.cacheDir
60 if (oldLogDir == null || oldLogDir.listFiles().isNullOrEmpty()) return // nothing to do
61
62 try {
63 // There's no point moving the log files. Let's delete those instead.
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 }
69 }
70}