Skip to content

Commit

Permalink
music: correctly parse data with new paths
Browse files Browse the repository at this point in the history
Accidental regression appeared due to inconsistent trailing slashes, so
we need to reimplement this using the path datatype itself.
  • Loading branch information
OxygenCobalt committed Jan 1, 2024
1 parent ec8e598 commit 6b9f686
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/music/fs/Fs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ value class Components private constructor(val components: List<String>) {
*/
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 (/).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 6b9f686

Please sign in to comment.