Skip to content

Commit d49f719

Browse files
committed
Revert "musikr: add subfolder exclusion prototype"
This reverts commit f2b1ba7.
1 parent f2b1ba7 commit d49f719

3 files changed

Lines changed: 21 additions & 73 deletions

File tree

musikr/src/main/java/org/oxycblt/musikr/Musikr.kt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,6 @@ interface Musikr {
5757
locations: List<MusicLocation>,
5858
onProgress: suspend (IndexingProgress) -> Unit = {}
5959
): LibraryResult
60-
61-
/**
62-
* Update a music location with a set of subdirectories to exclude from scanning.
63-
*
64-
* @param context The context to use for loading resources.
65-
* @param uri The URI of the music location to update.
66-
* @param excludedSubdirs The set of subdirectory names to exclude when scanning this location.
67-
* @return The updated [MusicLocation] or null if the location doesn't exist.
68-
*/
69-
fun updateLocationExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set<String>): MusicLocation?
70-
71-
/**
72-
* Create a new music location with a set of subdirectories to exclude from scanning.
73-
*
74-
* @param context The context to use for loading resources.
75-
* @param uri The URI of the music location to create.
76-
* @param excludedSubdirs The set of subdirectory names to exclude when scanning this location.
77-
* @return The new [MusicLocation] or null if the location couldn't be created.
78-
*/
79-
fun newLocationWithExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set<String>): MusicLocation?
8060

8161
companion object {
8262
/**
@@ -136,14 +116,6 @@ private class MusikrImpl(
136116
private val extractStep: ExtractStep,
137117
private val evaluateStep: EvaluateStep
138118
) : Musikr {
139-
override fun updateLocationExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set<String>): MusicLocation? {
140-
return MusicLocation.existing(context, uri, excludedSubdirs)
141-
}
142-
143-
override fun newLocationWithExclusions(context: Context, uri: android.net.Uri, excludedSubdirs: Set<String>): MusicLocation? {
144-
return MusicLocation.new(context, uri, excludedSubdirs)
145-
}
146-
147119
override suspend fun run(
148120
locations: List<MusicLocation>,
149121
onProgress: suspend (IndexingProgress) -> Unit

musikr/src/main/java/org/oxycblt/musikr/fs/MusicLocation.kt

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import org.oxycblt.musikr.fs.device.contentResolverSafe
2626
import org.oxycblt.musikr.fs.path.DocumentPathFactory
2727
import org.oxycblt.musikr.util.splitEscaped
2828

29-
class MusicLocation private constructor(val uri: Uri, val path: Path, val excludedSubdirs: Set<String> = emptySet()) {
29+
class MusicLocation private constructor(val uri: Uri, val path: Path) {
3030
override fun equals(other: Any?) = other is MusicLocation && uri == other.uri
3131

3232
override fun hashCode() = 31 * uri.hashCode()
3333

3434
override fun toString(): String = uri.toString()
3535

3636
companion object {
37-
fun new(context: Context, uri: Uri, excludedSubdirs: Set<String> = emptySet()): MusicLocation? {
37+
fun new(context: Context, uri: Uri): MusicLocation? {
3838
if (!DocumentsContract.isTreeUri(uri)) return null
3939
val documentPathFactory = DocumentPathFactory.from(context)
4040
val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null
@@ -47,10 +47,10 @@ class MusicLocation private constructor(val uri: Uri, val path: Path, val exclud
4747
uri,
4848
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
4949
}
50-
return MusicLocation(uri, path, excludedSubdirs)
50+
return MusicLocation(uri, path)
5151
}
5252

53-
fun existing(context: Context, uri: Uri, excludedSubdirs: Set<String> = emptySet()): MusicLocation? {
53+
fun existing(context: Context, uri: Uri): MusicLocation? {
5454
val documentPathFactory = DocumentPathFactory.from(context)
5555
if (!DocumentsContract.isTreeUri(uri)) return null
5656
val notPersisted =
@@ -59,28 +59,14 @@ class MusicLocation private constructor(val uri: Uri, val path: Path, val exclud
5959
}
6060
if (notPersisted) return null
6161
val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null
62-
return MusicLocation(uri, path, excludedSubdirs)
62+
return MusicLocation(uri, path)
6363
}
6464

65-
fun toString(list: List<MusicLocation>): String {
66-
return list.joinToString(";") { location ->
67-
val uriStr = location.uri.toString().replace(";", "\\;")
68-
val excludedSubdirsStr = location.excludedSubdirs.joinToString(",") { it.replace(",", "\\,").replace(";", "\\;") }
69-
if (excludedSubdirsStr.isEmpty()) uriStr else "$uriStr|$excludedSubdirsStr"
70-
}
71-
}
65+
fun toString(list: List<MusicLocation>) =
66+
list.joinToString(";") { it.uri.toString().replace(";", "\\;") }
7267

7368
fun existing(context: Context, string: String): List<MusicLocation> {
74-
return string.splitEscaped { it == ';' }.mapNotNull { entry ->
75-
val parts = entry.split("|", limit = 2)
76-
val uriStr = parts[0]
77-
val excludedSubdirs = if (parts.size > 1) {
78-
parts[1].splitEscaped { it == ',' }.toSet()
79-
} else {
80-
emptySet()
81-
}
82-
existing(context, Uri.parse(uriStr), excludedSubdirs)
83-
}
69+
return string.splitEscaped { it == ';' }.mapNotNull { existing(context, Uri.parse(it)) }
8470
}
8571
}
8672
}

musikr/src/main/java/org/oxycblt/musikr/fs/device/DeviceFS.kt

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.content.ContentResolver
2222
import android.content.Context
2323
import android.net.Uri
2424
import android.provider.DocumentsContract
25+
import android.util.Log
2526
import androidx.core.net.toUri
2627
import kotlinx.coroutines.CoroutineScope
2728
import kotlinx.coroutines.Dispatchers
@@ -39,7 +40,6 @@ import kotlinx.coroutines.flow.mapNotNull
3940
import kotlinx.coroutines.flow.merge
4041
import kotlinx.coroutines.flow.shareIn
4142
import kotlinx.coroutines.flow.takeWhile
42-
import kotlinx.coroutines.flow.transform
4343
import org.oxycblt.musikr.fs.MusicLocation
4444
import org.oxycblt.musikr.fs.Path
4545

@@ -76,7 +76,7 @@ private class DeviceFSImpl(
7676
if (modifiedMs == null) {
7777
return null
7878
}
79-
return query(location.uri, treeDocumentId, location.path, modifiedMs, null, fileTree, location.excludedSubdirs)
79+
return query(location.uri, treeDocumentId, location.path, modifiedMs, null, fileTree)
8080
}
8181

8282
private suspend fun query(
@@ -85,14 +85,13 @@ private class DeviceFSImpl(
8585
path: Path,
8686
modifiedMs: Long,
8787
parent: DeviceDirectory?,
88-
fileTree: FileTree,
89-
excludedSubdirs: Set<String> = emptySet()
88+
fileTree: FileTree
9089
): DeviceDirectory = coroutineScope {
9190
val uri = DocumentsContract.buildDocumentUriUsingTree(rootUri, treeDocumentId)
9291
val cached = fileTree.queryDirectory(uri)
9392
if (cached != null && cached.modifiedMs == modifiedMs) {
9493
return@coroutineScope hydrateCached(
95-
cached = cached, parentDir = parent, path = path, fileTree = fileTree, excludedSubdirs = excludedSubdirs)
94+
cached = cached, parentDir = parent, path = path, fileTree = fileTree)
9695
}
9796
val dir =
9897
DeviceDirectoryImpl(
@@ -103,6 +102,7 @@ private class DeviceFSImpl(
103102
children = emptyFlow())
104103
dir.children =
105104
flow {
105+
Log.d("DeviceFS", "Querying $uri")
106106
contentResolver.useQuery(
107107
DocumentsContract.buildChildDocumentsUriUsingTree(
108108
rootUri,
@@ -129,6 +129,8 @@ private class DeviceFSImpl(
129129
val childSubdirUris = mutableListOf<String>()
130130
val childFileUris = mutableListOf<String>()
131131

132+
val subqueries = mutableListOf<DeviceDirectory>()
133+
132134
while (cursor.moveToNext()) {
133135
val childId = cursor.getString(childUriIndex)
134136
val displayName = cursor.getString(displayNameIndex)
@@ -143,23 +145,18 @@ private class DeviceFSImpl(
143145
val lastModified = cursor.getLong(lastModifiedIndex)
144146

145147
if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
146-
// Skip this directory if it's in the excluded list
147-
if (displayName in excludedSubdirs) {
148-
continue
149-
}
150-
151148
val subdir =
152149
query(
153150
rootUri = rootUri,
154151
treeDocumentId = childId,
155152
path = newPath,
156153
modifiedMs = modifiedMs,
157154
parent = dir,
158-
fileTree = fileTree,
159-
excludedSubdirs = excludedSubdirs)
155+
fileTree = fileTree)
160156
childSubdirUris.add(subdir.uri.toString())
161157
emit(StreamedFile.More(subdir))
162158
} else {
159+
Log.d("DeviceFS", "Querying file $childId")
163160
val size = cursor.getLong(sizeIndex)
164161
val childUri =
165162
DocumentsContract.buildDocumentUriUsingTree(
@@ -205,8 +202,7 @@ private class DeviceFSImpl(
205202
cached: CachedDirectory,
206203
parentDir: DeviceDirectory?,
207204
path: Path,
208-
fileTree: FileTree,
209-
excludedSubdirs: Set<String> = emptySet()
205+
fileTree: FileTree
210206
): DeviceDirectory = coroutineScope {
211207
val dir =
212208
DeviceDirectoryImpl(
@@ -219,23 +215,17 @@ private class DeviceFSImpl(
219215
flow {
220216
emitAll(
221217
merge(
222-
cached.subdirUris.asFlow().transform { subdirUriString ->
218+
cached.subdirUris.asFlow().map { subdirUriString ->
223219
val subdirUri = subdirUriString.toUri()
224220
val cachedSubdir =
225221
requireNotNull(fileTree.queryDirectory(subdirUri)) {
226222
"No cached subdir for $subdirUri, malformed cache! Rescan needed."
227223
}
228-
// Skip this directory if it's in the excluded list
229-
if (cachedSubdir.name in excludedSubdirs) {
230-
return@transform
231-
}
232-
233-
emit(hydrateCached(
224+
hydrateCached(
234225
cachedSubdir,
235226
dir,
236227
dir.path.file(cachedSubdir.name),
237-
fileTree,
238-
excludedSubdirs))
228+
fileTree)
239229
},
240230
cached.fileUris.asFlow().map {
241231
val cachedFile = requireNotNull(fileTree.queryFile(it.toUri()))

0 commit comments

Comments
 (0)