fix(import): skip files trashed under their old display name

HyperOS renames a deleted file to .trashed-… but keeps reporting its old display name, so only the document id shows it.
This commit is contained in:
YaqiongWu authored and Anthonyy232 committed 2026-11-18 08:27:33 -08:00
1 parent 16f5a1682b
commit 073df232f2
2 files changed
+9 -5

No files matched your search

@@ -98,17 +98,19 @@ class DocumentAccessInstrumentedTest {
assertEquals(2, provider.queries)
}
@Test fun scanSkipsTrashNamesButKeepsImagesInHiddenFolders() = runBlocking {
@Test fun scanSkipsTrashedFilesButKeepsImagesInHiddenFolders() = runBlocking {
provider.answer = { uri ->
when (DocumentsContract.getDocumentId(uri)) {
"root" -> directoryCursor().apply {
addRow(arrayOf<Any>("trashed", ".trashed54970.jpg", "image/jpeg", 1L))
addRow(arrayOf<Any>("trash", ".Trash-123.png", "image/png", 2L))
addRow(arrayOf<Any>("walls", ".walls", DocumentsContract.Document.MIME_TYPE_DIR, 0L))
addRow(arrayOf<Any>("primary:Pictures/.trashed-1797497267-old.jpg", "old.jpg", "image/jpeg", 5L))
addRow(arrayOf<Any>("primary:.trashed-1797497267-top.jpg", "top.jpg", "image/jpeg", 6L))
addRow(arrayOf<Any>("primary:Pictures/.walls", ".walls", DocumentsContract.Document.MIME_TYPE_DIR, 0L))
addRow(arrayOf<Any>("plain", "photo.jpg", "image/jpeg", 3L))
}
"walls" -> directoryCursor().apply {
addRow(arrayOf<Any>("hidden-photo", "wall.png", "image/png", 4L))
"primary:Pictures/.walls" -> directoryCursor().apply {
addRow(arrayOf<Any>("primary:Pictures/.walls/wall.png", "wall.png", "image/png", 4L))
}
else -> directoryCursor()
}
@@ -124,7 +124,9 @@ internal suspend fun Uri.scanFolderImages(context: Context, onProgress: (found:
if (!visitedDocuments.add(documentId)) continue
val name = cursor.getString(nameColumn) ?: continue
// Galleries rename deleted files in place: .trashed-…, .Trash-…
if (name.startsWith(".trash", ignoreCase = true)) continue
// HyperOS keeps reporting the old display name, so the id is checked too.
val fileName = documentId.substringAfterLast('/').substringAfterLast(':')
if (listOf(name, fileName).any { it.startsWith(".trash", ignoreCase = true) }) continue
if (cursor.getString(mimeColumn) == DocumentsContract.Document.MIME_TYPE_DIR) {
pendingDirs.addLast(documentId)
} else {