mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 15:40:16 +00:00
fix(utils): clarify that the to_string().contains() is necessary due to CString16
This commit is contained in:
10
src/utils.rs
10
src/utils.rs
@@ -27,6 +27,12 @@ pub fn text_to_device_path(path: &str) -> Result<PoolDevicePath> {
|
|||||||
.context("unable to convert text to device path")
|
.context("unable to convert text to device path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if a [CString16] contains a char `c`.
|
||||||
|
/// We need to call to_string() because CString16 doesn't support `contains` with a char.
|
||||||
|
fn cstring16_contains_char(string: &CString16, c: char) -> bool {
|
||||||
|
string.to_string().contains(c)
|
||||||
|
}
|
||||||
|
|
||||||
/// Grabs the root part of the `path`.
|
/// Grabs the root part of the `path`.
|
||||||
/// For example, given "PciRoot(0x0)/Pci(0x4,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\BOOT\BOOTX64.efi"
|
/// For example, given "PciRoot(0x0)/Pci(0x4,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\BOOT\BOOTX64.efi"
|
||||||
/// it will give "PciRoot(0x0)/Pci(0x4,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)"
|
/// it will give "PciRoot(0x0)/Pci(0x4,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)"
|
||||||
@@ -37,7 +43,7 @@ pub fn device_path_root(path: &DevicePath) -> Result<String> {
|
|||||||
let item = item.to_string(DisplayOnly(false), AllowShortcuts(false));
|
let item = item.to_string(DisplayOnly(false), AllowShortcuts(false));
|
||||||
if item
|
if item
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|item| item.to_string().contains('('))
|
.map(|item| cstring16_contains_char(item, '('))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
Some(item.unwrap_or_default())
|
Some(item.unwrap_or_default())
|
||||||
@@ -62,7 +68,7 @@ pub fn device_path_subpath(path: &DevicePath) -> Result<String> {
|
|||||||
let item = item.to_string(DisplayOnly(false), AllowShortcuts(false));
|
let item = item.to_string(DisplayOnly(false), AllowShortcuts(false));
|
||||||
if item
|
if item
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|item| item.to_string().contains('('))
|
.map(|item| cstring16_contains_char(item, '('))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user