From 6b9f6862affc45abf41afd541b559c1c279f9177 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 1 Jan 2024 11:47:21 -0700 Subject: [PATCH] music: correctly parse data with new paths Accidental regression appeared due to inconsistent trailing slashes, so we need to reimplement this using the path datatype itself. --- app/src/main/java/org/oxycblt/auxio/music/fs/Fs.kt | 12 ++++++++++++ .../oxycblt/auxio/music/fs/MediaStoreExtractor.kt | 9 ++++----- 2 files changed, 16 insertions(+), 5 deletions(-) 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 } }