Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions rust/agama-lib/src/utils/transfer/file_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ impl FileSystemsReader {
re.captures_iter(lsblk_string).map(|c| c.extract())
{
// Use the shorter path as the canonical mount point.
let mut mounts = mount_points.split("\\x0a").collect::<Vec<_>>();
mounts.sort_by(|a, b| a.len().cmp(&b.len()));
let mount_point = if mount_points.is_empty() {
None
} else {
let mut mounts = mount_points.split("\\x0a").collect::<Vec<_>>();
mounts.sort_by(|a, b| a.len().cmp(&b.len()));
mounts.first().map(|m| PathBuf::from(m))
};

let mut file_system = FileSystem {
block_device: block_device
Expand All @@ -227,7 +232,7 @@ impl FileSystemsReader {
} else {
Some(fstype.to_string())
},
mount_point: mounts.first().map(|m| PathBuf::from(m)),
mount_point,
transport: if transport.is_empty() {
None
} else {
Expand Down Expand Up @@ -333,9 +338,15 @@ KNAME="/dev/dm-1" FSTYPE="swap" MOUNTPOINTS="[SWAP]" TRAN="" LABEL=""
assert_eq!(file_systems.len(), 4);

let dm0 = file_systems
.into_iter()
.iter()
.find(|fs| &fs.block_device == "dm-0")
.unwrap();
assert_eq!(dm0.mount_point.unwrap(), PathBuf::from("/"));
assert_eq!(dm0.mount_point.as_ref().unwrap(), &PathBuf::from("/"));

let sda2 = file_systems
.iter()
.find(|fs| &fs.block_device == "sda2")
.unwrap();
assert_eq!(sda2.mount_point, None);
}
}