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.
This commit is contained in:
parent
ec8e598d3b
commit
6b9f6862af
2 changed files with 16 additions and 5 deletions
|
@ -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 (/).
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue