diff options
author | pacien | 2023-07-29 23:32:28 +0200 |
---|---|---|
committer | pacien | 2023-07-30 03:53:20 +0200 |
commit | 564e675c0a44dfb3b914d1d4307fdde844ad082f (patch) | |
tree | 9889a0f68e8277d807165a8d4d4b6533cd009998 /app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | |
parent | dfb26a0d2c95d56f69f5e1e0c255d9d5d6788120 (diff) | |
download | tincapp-564e675c0a44dfb3b914d1d4307fdde844ad082f.tar.gz |
storage: move app and tinc daemon logs to user-accessible cache directory
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context/AppPaths.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/AppPaths.kt | 11 |
1 files changed, 6 insertions, 5 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 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 @@ | |||
1 | /* | 1 | /* |
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | 2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon |
3 | * Copyright (C) 2017-2020 Pacien TRAN-GIRARD | 3 | * Copyright (C) 2017-2023 Pacien TRAN-GIRARD |
4 | * | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | 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 | 6 | * it under the terms of the GNU General Public License as published by |
@@ -49,10 +49,11 @@ object AppPaths { | |||
49 | 49 | ||
50 | private val context by lazy { App.getContext() } | 50 | private val context by lazy { App.getContext() } |
51 | 51 | ||
52 | private fun cacheDir() = context.cacheDir!! | 52 | private fun privateCacheDir() = context.cacheDir!! |
53 | private fun publicCacheDir() = context.externalCacheDir!! | ||
53 | private fun binDir() = File(context.applicationInfo.nativeLibraryDir) | 54 | private fun binDir() = File(context.applicationInfo.nativeLibraryDir) |
54 | fun runtimeDir() = withDir(File(cacheDir(), APP_TINC_RUNTIME_DIR)) | 55 | fun runtimeDir() = withDir(File(privateCacheDir(), APP_TINC_RUNTIME_DIR)) |
55 | fun logDir() = withDir(File(cacheDir(), APP_LOG_DIR)) | 56 | fun logDir() = withDir(File(publicCacheDir(), APP_LOG_DIR)) |
56 | fun confDir() = withDir(File(context.filesDir!!, APP_TINC_NETWORKS_DIR)) | 57 | fun confDir() = withDir(File(context.filesDir!!, APP_TINC_NETWORKS_DIR)) |
57 | 58 | ||
58 | fun confDir(netName: String) = File(confDir(), netName) | 59 | fun confDir(netName: String) = File(confDir(), netName) |
@@ -63,7 +64,7 @@ object AppPaths { | |||
63 | fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName)) | 64 | fun logFile(netName: String) = File(logDir(), String.format(LOGFILE_FORMAT, netName)) |
64 | fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName)) | 65 | fun pidFile(netName: String) = File(runtimeDir(), String.format(PIDFILE_FORMAT, netName)) |
65 | fun appLogFile() = File(logDir(), APPLOG_FILE) | 66 | fun appLogFile() = File(logDir(), APPLOG_FILE) |
66 | fun crashFlagFile() = File(cacheDir(), CRASHFLAG_FILE) | 67 | fun crashFlagFile() = File(privateCacheDir(), CRASHFLAG_FILE) |
67 | 68 | ||
68 | fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } | 69 | fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } |
69 | fun withDir(f: File) = f.apply { if (!exists()) mkdirs() } | 70 | fun withDir(f: File) = f.apply { if (!exists()) mkdirs() } |