Closed clifforous closed 2 years ago
Oh yeah that makes total sense, feel free to open a MR :)
I guess we can have DEFAULT = 0
and then have the
registerFileSystem(creator: FileSystemCreator) {
registerFileSystem(creator, 1)
}
Then this would not happen by accident anymore
Problem
I am registering a
FileSystemCreator
via an initializer block in the Main Activity companion object.The FileSystemFactory object initializer block registers the default
Fat32FileSystemCreator
before that FileSystemCreator. ThecreateFileSystem
function then iterates in the order the creators were registered so thatFat32FileSystemCreator
is always evaluated first.I would like my FileSystemCreator to be evaluated before the default creator so that I consistently use the custom creator for FAT12, FAT16, and FAT32.
Proposed Solution
Add a mechanism of assigning an order. This could just be adding an additional function signature such as:
fun registerFileSystem(creator: FileSystemCreator, priority: Int)
A constant value for the priority default file system creator could be exposed so that registered creators can be ordered before or after the default. The existing function can continue to behave the same way so as to make the change non-breaking.
Alternatively, could just remove the initializer block from FileSystemFactory and lazily add the Fat32FileSystemCreator at the time of the call to
createFileSystem
if there are no registered creators.Code where problem occurs
https://github.com/magnusja/libaums/blob/develop/libaums/src/main/java/me/jahnen/libaums/core/fs/FileSystemFactory.kt#L48