Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always ensure media temp dir exists #1790

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1790.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Always ensure media temp dir exists
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import java.util.logging.Logger
* Will be planted in Timber.
*/
class VectorFileLogger(
context: Context,
private val context: Context,
// private val vectorPreferences: VectorPreferences
private val dispatcher: CoroutineDispatcher = Dispatchers.IO,
) : Timber.Tree() {
Expand Down Expand Up @@ -66,7 +66,9 @@ class VectorFileLogger(
}

private val fileHandler: FileHandler?
private val cacheDirectory = File(context.cacheDir, "logs")
private val cacheDirectory get() = File(context.cacheDir, "logs").apply {
if (!exists()) mkdirs()
}
private var fileNamePrefix = "logs"

private val prioPrefixes = mapOf(
Expand All @@ -79,10 +81,6 @@ class VectorFileLogger(
)

init {
if (!cacheDirectory.exists()) {
cacheDirectory.mkdirs()
}

for (i in 0..15) {
val file = File(cacheDirectory, "elementLogs.${i}.txt")
file.safeDelete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ import java.io.File
import org.matrix.rustcomponents.sdk.MediaSource as RustMediaSource

class RustMediaLoader(
baseCacheDirectory: File,
private val baseCacheDirectory: File,
dispatchers: CoroutineDispatchers,
private val innerClient: Client,
) : MatrixMediaLoader {

@OptIn(ExperimentalCoroutinesApi::class)
private val mediaDispatcher = dispatchers.io.limitedParallelism(32)
private val cacheDirectory = File(baseCacheDirectory, "temp/media").apply {
if (!exists()) {
mkdirs()
private val cacheDirectory
get() = File(baseCacheDirectory, "temp/media").apply {
if (!exists()) mkdirs() // Must always ensure that this directory exists because "Clear cache" does not restart an app's process.
}
}

@OptIn(ExperimentalUnsignedTypes::class)
override suspend fun loadMediaContent(source: MediaSource): Result<ByteArray> =
Expand Down