• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash-android / 10075269522

24 Jul 2024 10:50AM UTC coverage: 69.676% (+4.4%) from 65.26%
10075269522

Pull #64

github

web-flow
Merge edfc3794f into 4fb5c6315
Pull Request #64: tests: test metrics sender

178 of 280 branches covered (63.57%)

Branch coverage included in aggregate %.

532 of 739 relevant lines covered (71.99%)

4.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/unleashandroidsdk/src/main/java/io/getunleash/android/cache/CacheDirectoryProvider.kt
1
package io.getunleash.android.cache
2

3
import android.content.Context
4
import android.util.Log
5
import io.getunleash.android.backup.LocalStorageConfig
6
import java.io.File
7

8
class CacheDirectoryProvider(private val config: LocalStorageConfig, private val context: Context) {
×
9

10
    companion object {
11
        private const val TAG = "CacheDirProvider"
12
    }
13
    fun getCacheDirectory(tempDirName: String, deleteOnShutdown: Boolean = false): File {
×
14
        val tempStorageDir: File = config.dir?.let { File(it) } ?: context.cacheDir
×
15
        val tempDir = File(tempStorageDir, tempDirName)
×
16
        if (!createDirectoryIfNotExists(tempDir)) {
×
17
            Log.w(TAG, "Failed to create directory ${tempDir.absolutePath}")
×
18
        } else {
19
            if (deleteOnShutdown) addShutdownHook(tempDir)
×
20
        }
21
        return tempDir
×
22
    }
23

24
    private fun createDirectoryIfNotExists(file: File): Boolean {
25
        if (file.exists()) {
×
26
            Log.d(TAG, "Directory ${file.absolutePath} already exists")
×
27
            return true
×
28
        }
29
        if (file.mkdirs()) {
×
30
            Log.d(TAG, "Created directory ${file.absolutePath}")
×
31
            return true
×
32
        }
33
        Log.w(TAG, "Failed to create directory ${file.absolutePath}")
×
34
        return false
×
35
    }
36

37
    private fun addShutdownHook(file: File) {
38
        Runtime.getRuntime().addShutdownHook(DeleteFileShutdownHook(file))
×
39
    }
×
40

41
    private class DeleteFileShutdownHook(file: File) : Thread(Runnable {
×
42
        file.deleteRecursively()
×
43
    })
×
44
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc