Skip to content

Commit

Permalink
music: more path interpreter guards
Browse files Browse the repository at this point in the history
  • Loading branch information
OxygenCobalt committed Jan 1, 2024
1 parent 77f0bbe commit b10caae
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,11 @@ private class DataPathInterpreter(
val volumePath = volume.components ?: continue
if (volumePath.contains(data)) {
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 {
Expand Down Expand Up @@ -431,16 +433,16 @@ private class VolumePathInterpreter(private val cursor: Cursor, volumeManager: V
// Find the StorageVolume whose MediaStore name corresponds to it.
val volumeName = cursor.getString(volumeIndex)
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
// in manually.
val relativePath = cursor.getString(relativePathIndex)
val displayName = cursor.getString(displayNameIndex)
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 {
Expand Down

0 comments on commit b10caae

Please sign in to comment.