diff --git a/app/src/main/java/org/oxycblt/auxio/music/fs/Fs.kt b/app/src/main/java/org/oxycblt/auxio/music/fs/Fs.kt index c8b26523c..2639ec207 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/fs/Fs.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/fs/Fs.kt @@ -146,6 +146,18 @@ value class Components private constructor(val components: List) { */ fun child(other: Components) = Components(components + other.components) + /** + * Returns the given [Components] has a prefix equal to this [Components] instance. Effectively, + * as if the given [Components] instance was a child of this [Components] instance. + */ + fun contains(other: Components): Boolean { + if (other.components.size < components.size) { + return false + } + + return components == other.components.take(components.size) + } + companion object { /** * Parses a path string into a [Components] instance by the unix path separator (/). diff --git a/app/src/main/java/org/oxycblt/auxio/music/fs/MediaStoreExtractor.kt b/app/src/main/java/org/oxycblt/auxio/music/fs/MediaStoreExtractor.kt index 137692389..ccb5ab738 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/fs/MediaStoreExtractor.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/fs/MediaStoreExtractor.kt @@ -390,12 +390,11 @@ class DataPathInterpreter(private val cursor: Cursor, private val volumeManager: // Find the volume that transforms the DATA column into a relative path. This is // the Directory we will use. - val rawPath = data.substringBeforeLast(File.separatorChar) + val rawPath = Components.parseUnix(data) for (volume in volumes) { - val volumePath = (volume.components ?: continue).toString() - val strippedPath = rawPath.removePrefix(volumePath) - if (strippedPath != rawPath) { - rawSong.directory = Path(volume, Components.parseUnix(strippedPath)) + val volumePath = volume.components ?: continue + if (volumePath.contains(rawPath)) { + rawSong.directory = Path(volume, rawPath.depth(volumePath.components.size)) break } }