Skip to content

Commit

Permalink
fix: IO - use absolute path for cached copy
Browse files Browse the repository at this point in the history
  • Loading branch information
criticalAY authored and BrayanDSO committed Mar 26, 2024
1 parent 0ef9363 commit 027a96c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.ichi2.anki.*
import com.ichi2.anki.dialogs.DialogHandler
import com.ichi2.anki.dialogs.DialogHandlerMessage
import com.ichi2.anki.dialogs.ImportDialog
import com.ichi2.annotations.NeedsTest
import com.ichi2.compat.CompatHelper
import org.jetbrains.annotations.Contract
import timber.log.Timber
Expand Down Expand Up @@ -126,11 +127,12 @@ object ImportUtils {
}
}

@NeedsTest("Check file name is absolute")
fun getFileCachedCopy(context: Context, uri: Uri): String? {
val filename = ensureValidLength(getFileNameFromContentProvider(context, uri) ?: return null)
val tempPath = Uri.fromFile(File(context.cacheDir, filename)).encodedPath!!
return if (copyFileToCache(context, uri, tempPath)) {
tempPath
val tempFile = File(context.cacheDir, filename)
return if (copyFileToCache(context, uri, tempFile.absolutePath)) {
tempFile.absolutePath
} else {
null
}
Expand Down

0 comments on commit 027a96c

Please sign in to comment.