Skip to content

Commit b7d2941

Browse files
committed
fix: tests
1 parent 2970c69 commit b7d2941

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

app/src/main/java/to/bitkit/repositories/LogsRepo.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ class LogsRepo @Inject constructor(
5858
/** Lists log files sorted by newest first */
5959
suspend fun getLogs(): Result<List<LogFile>> = withContext(bgDispatcher) {
6060
try {
61-
val logDir = File(Env.logDir)
62-
if (!logDir.exists()) {
63-
return@withContext Result.failure(Exception("Logs dir not found"))
64-
}
61+
val logDir = runCatching { File(Env.logDir) }.getOrElse { return@withContext Result.failure(it) }
62+
if (!logDir.exists()) return@withContext Result.failure(Exception("Logs dir not found"))
6563

6664
val logFiles = logDir
6765
.listFiles { file -> file.extension == "log" }

app/src/main/java/to/bitkit/utils/Logger.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class LogSaverImpl(private val sessionFilePath: String) : LogSaver {
173173
}
174174

175175
override fun save(message: String) {
176+
if (sessionFilePath.isEmpty()) return
177+
176178
queue.launch {
177179
runCatching {
178180
FileOutputStream(File(sessionFilePath), true).use { stream ->
@@ -186,10 +188,10 @@ class LogSaverImpl(private val sessionFilePath: String) : LogSaver {
186188

187189
private fun cleanupOldLogFiles(maxTotalSizeMB: Int = 20) {
188190
Log.v(APP, "Deleting old log files…")
189-
val baseDir = File(Env.logDir)
190-
if (!baseDir.exists()) return
191+
val logDir = runCatching { File(Env.logDir) }.getOrElse { return }
192+
if (!logDir.exists()) return
191193

192-
val logFiles = baseDir
194+
val logFiles = logDir
193195
.listFiles { file -> file.extension == "log" }
194196
?.map { file -> Triple(file, file.length(), file.lastModified()) }
195197
?: return
@@ -241,9 +243,12 @@ class LdkLogWriter(
241243
}
242244

243245
private fun buildSessionLogFilePath(source: LogSource): String {
246+
val logDir = runCatching { File(Env.logDir) }.getOrElse { return "" }
247+
if (!logDir.exists()) return ""
248+
244249
val sourceName = source.name.lowercase()
245250
val timestamp = utcDateFormatterOf(DatePattern.LOG_FILE).format(Date())
246-
val sessionLogFilePath = File(Env.logDir).resolve("${sourceName}_$timestamp.log").path
251+
val sessionLogFilePath = logDir.resolve("${sourceName}_$timestamp.log").path
247252
Log.i(APP, "Log session for '$sourceName' initialized with file path: '$sessionLogFilePath'")
248253
return sessionLogFilePath
249254
}

app/src/main/java/to/bitkit/viewmodels/LogsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class LogsViewModel @Inject constructor(
8484
fun deleteAllLogs() {
8585
viewModelScope.launch {
8686
try {
87-
val logDir = File(Env.logDir)
87+
val logDir = runCatching { File(Env.logDir) }.getOrElse { return@launch }
8888
logDir.listFiles { file ->
8989
file.extension == "log"
9090
}?.forEach { file ->

0 commit comments

Comments
 (0)