Skip to content
This repository was archived by the owner on Aug 26, 2026. It is now read-only.
This repository was archived by the owner on Aug 26, 2026. It is now read-only.

[Fix] Implement proper temp file cleanup after image upload in AnalysisRepositoryImpl #165

Description

@coderabbitai

Summary

In data/analysis/impl/src/main/java/com/metasearch/android/data/analysis/impl/repository/AnalysisRepositoryImpl.kt, the finally block inside uploadImages has fileRepository.deleteFile(tempFile) commented out as a temporary workaround to prevent a race condition where OkHttp had not fully flushed data to the server before the temp file was deleted (causing 'Corrupt JPEG' errors).

While this prevents the corruption issue, it causes temp files to accumulate in cacheDir over time, leading to unnecessary disk usage.

Steps to Reproduce

  1. Trigger image uploads via uploadImages() in AnalysisRepositoryImpl
  2. Observe that temp files in cacheDir are never cleaned up

Proposed Solutions

One of the following approaches should be implemented:

  1. Deferred coroutine deletion – After the upload completes, schedule cleanup with a short delay:
    CoroutineScope(Dispatchers.IO).launch { delay(...); fileRepository.deleteFile(tempFile) }
  2. OkHttp streaming – Stream directly from the original URI as a RequestBody to avoid creating a temp file altogether.
  3. Pending-files tracker – Track pending temp files and clean them up in a lifecycle callback or a periodic background job.

References

/cc @komodgn

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions