music: more path interpreter guards

This commit is contained in:
Alexander Capehart 2024-01-01 12:25:49 -07:00
parent 77f0bbe614
commit b10caaef54
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -379,9 +379,11 @@ private class DataPathInterpreter(
val volumePath = volume.components ?: continue val volumePath = volume.components ?: continue
if (volumePath.contains(data)) { if (volumePath.contains(data)) {
rawSong.path = Path(volume, data.depth(volumePath.components.size)) rawSong.path = Path(volume, data.depth(volumePath.components.size))
break return
} }
} }
throw IllegalStateException("Could not find volume for path $data (tried: $volumes)")
} }
class Factory(private val volumeManager: VolumeManager) : PathInterpreter.Factory { class Factory(private val volumeManager: VolumeManager) : PathInterpreter.Factory {
@ -431,17 +433,17 @@ private class VolumePathInterpreter(private val cursor: Cursor, volumeManager: V
// Find the StorageVolume whose MediaStore name corresponds to it. // Find the StorageVolume whose MediaStore name corresponds to it.
val volumeName = cursor.getString(volumeIndex) val volumeName = cursor.getString(volumeIndex)
val volume = volumes.find { it.mediaStoreName == volumeName } val volume = volumes.find { it.mediaStoreName == volumeName }
if (volume == null) {
throw IllegalStateException("Could not find volume for name $volumeName")
}
// Relative path does not include file name, must use DISPLAY_NAME and add it // Relative path does not include file name, must use DISPLAY_NAME and add it
// in manually. // in manually.
val relativePath = cursor.getString(relativePathIndex) val relativePath = cursor.getString(relativePathIndex)
val displayName = cursor.getString(displayNameIndex) val displayName = cursor.getString(displayNameIndex)
val components = Components.parseUnix(relativePath).child(displayName) val components = Components.parseUnix(relativePath).child(displayName)
if (volume != null) {
rawSong.path = Path(volume, components) rawSong.path = Path(volume, components)
} }
}
class Factory(private val volumeManager: VolumeManager) : PathInterpreter.Factory { class Factory(private val volumeManager: VolumeManager) : PathInterpreter.Factory {
override val projection: Array<String> override val projection: Array<String>