On 02/27/2017 10:21 AM, Arvin Schnell wrote:
> On Mon, Feb 27, 2017 at 08:51:01AM +0100, Ancor Gonzalez Sosa wrote:
>> Since the original thread is already ruined with discussions about
>> concrete API design details that were not the main topic of my question,
>> I will try once again from scratch.
> 
> Sorry to bother you, but if you continue to bring such bad
> examples this thread will also be ruined by the end of the day.
> 
>> a_filesystem.all_disks
>>
>> But the user is expected to do this
>>
>> blk_dev = a_filesystem.blk_devices[0]
>> if Storage.encryption?(blk_device)
>>   blk_device = Storage.to_encryption(blk_device).blk_device
>> end
>> return [Storage.to_disk(blk_dev)] if Storage.disk?(blk_dev)
>> if Storage.partition?(blk_device)
>>   partition = Storage.to_partition(blk_device)
>>   if Storage.disk?(partition.partition_table.partitionable)
>>     return [Storage.to_disk(partition.partition_table.partitionable)]
>>   else
>>     # MD case
>>   end
>> elsif Storage.lvm_lv?(blk_device)
>>   # The LVM case, which is double the size than the partition one
>> end
> 
> Or just:
> 
>   for filesystem.ancestors do |device| do
>     ret = []
>     ret << device if disk?(device)
>     return ret
>   done

Ok, I'll bite the hook.

That returns objects of class Device, not disks. You forgot the
downcast. So it would be
ret << Storage.to_disk(device) if disk?(device)

And as I have tried to explain (and apparently failed), checking for the
real type of something and then performing a downcast is already non-ruby.

But let's try another less simplistic example, in which I expect at
least some downcasts in the bare libstorage-ng version:

For a given disk, an array of its encrypted logical partitions
containing an ext3 filesystem

One possible option with my suggested ruby-like API
the_disk.all_partitions.with(type: :logical).select do |part|
  !part.all_encryptions.all_filesystems.with(type: :ext3).empty?
end

Arvin, can you please provide the bare libstorage-ng example so we save
the correction step. ;-)

Cheers.
-- 
Ancor González Sosa
YaST Team at SUSE Linux GmbH
-- 
To unsubscribe, e-mail: [email protected]
To contact the owner, e-mail: [email protected]

Reply via email to