From e9da6a8dc94556ae33d97fe852401ee58911acb4 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Mon, 19 Aug 2024 03:39:52 +0300 Subject: [PATCH] basic subvol support --- src/manual_partitioning_page/mod.rs | 67 +++++++++++++++++++---------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/src/manual_partitioning_page/mod.rs b/src/manual_partitioning_page/mod.rs index 7e2bfd1..5d763b3 100644 --- a/src/manual_partitioning_page/mod.rs +++ b/src/manual_partitioning_page/mod.rs @@ -35,7 +35,7 @@ pub fn manual_partitioning_page( let partition_array_refcell = Rc::new(RefCell::new(get_partitions())); let used_partition_array_refcell: Rc>> = Rc::new(RefCell::default()); - let do_used_part_check_refcell = Rc::new(RefCell::new(true)); + let subvol_partition_array_refcell: Rc>> = Rc::new(RefCell::default()); // @@ -75,7 +75,7 @@ pub fn manual_partitioning_page( &partition_changed_action, &language_changed_action, &used_partition_array_refcell, - &do_used_part_check_refcell, + &subvol_partition_array_refcell, ); content_box.append(&drive_mounts_viewport); @@ -146,7 +146,7 @@ fn create_efi_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - do_used_part_check_refcell: &Rc>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -266,7 +266,7 @@ fn create_efi_row( never: Rc::new(RefCell::new(false)), } }; - post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &subvol_partition_array_refcell); partition_scroll_child.append(&partition_row_struct.widget); } @@ -300,7 +300,7 @@ fn create_boot_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - do_used_part_check_refcell: &Rc>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -420,7 +420,7 @@ fn create_boot_row( never: Rc::new(RefCell::new(false)), } }; - post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &subvol_partition_array_refcell); partition_scroll_child.append(&partition_row_struct.widget); } @@ -454,7 +454,7 @@ fn create_root_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - do_used_part_check_refcell: &Rc>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -579,7 +579,7 @@ fn create_root_row( never: Rc::new(RefCell::new(false)), } }; - post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &subvol_partition_array_refcell); partition_scroll_child.append(&partition_row_struct.widget); } @@ -613,7 +613,7 @@ fn create_mount_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - do_used_part_check_refcell: &Rc>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -703,7 +703,7 @@ fn create_mount_row( never: Rc::new(RefCell::new(false)), } }; - post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &do_used_part_check_refcell); + post_check_drive_mount(&row, &partition_row_struct, &partition_button, &partition_changed_action, &partition, &used_partition_array_refcell, &subvol_partition_array_refcell); partition_scroll_child.append(&partition_row_struct.widget); } @@ -730,7 +730,7 @@ fn create_mount_row( ); } -fn post_check_drive_mount(row: &DriveMountRow, partition_row_struct: &PartitionRow, partition_button: >k::CheckButton, partition_changed_action: &gio::SimpleAction, partition: &Partition, used_partition_array_refcell: &Rc>>, do_used_part_check_refcell: &Rc>) { +fn post_check_drive_mount(row: &DriveMountRow, partition_row_struct: &PartitionRow, partition_button: >k::CheckButton, partition_changed_action: &gio::SimpleAction, partition: &Partition, used_partition_array_refcell: &Rc>>, subvol_partition_array_refcell: &Rc>>) { partition_row_struct.widget.add_prefix(partition_button); partition_button.connect_toggled(clone!( #[weak] @@ -761,8 +761,6 @@ fn post_check_drive_mount(row: &DriveMountRow, partition_row_struct: &PartitionR #[strong] partition, #[strong] - partition_changed_action, - #[strong] row, move |_| { if row.mountpoint() == "[SWAP]" { @@ -777,6 +775,26 @@ fn post_check_drive_mount(row: &DriveMountRow, partition_row_struct: &PartitionR } )); + row.connect_mountopts_notify(clone!( + #[strong] + partition, + #[strong] + partition_changed_action, + #[strong] + subvol_partition_array_refcell, + #[strong] + row, + move |_| { + if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") { + (*subvol_partition_array_refcell.borrow_mut()).push(partition.part_name.to_string()); + } else { + (*subvol_partition_array_refcell.borrow_mut()) + .retain(|x| x != &partition.part_name); + } + partition_changed_action.activate(None); + } + )); + partition_changed_action.connect_activate(clone!( #[strong] partition_row_struct, @@ -787,22 +805,27 @@ fn post_check_drive_mount(row: &DriveMountRow, partition_row_struct: &PartitionR #[strong] used_partition_array_refcell, #[strong] - do_used_part_check_refcell, + subvol_partition_array_refcell, move |_, _| { - if *do_used_part_check_refcell.borrow() == true { let part_name = &partition.part_name; let used_partition_array = used_partition_array_refcell.borrow(); + let subvol_partition_array = subvol_partition_array_refcell.borrow(); if used_partition_array .iter() .any(|e| part_name == e && part_name != &row.partition()) { partition_row_struct.widget.set_sensitive(false); (*partition_row_struct.used.borrow_mut()) = true; + if subvol_partition_array + .iter() + .any(|e| e == part_name) + { + partition_row_struct.widget.set_sensitive(true); + } } else if *partition_row_struct.never.borrow() == false { partition_row_struct.widget.set_sensitive(true); (*partition_row_struct.used.borrow_mut()) = false; } - } } )); } @@ -814,7 +837,7 @@ fn create_hardcoded_rows( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - do_used_part_check_refcell: &Rc>, + subvol_partition_array_refcell: &Rc>>, ) { let drive_mount_add_button = gtk::Button::builder() .icon_name("list-add") @@ -829,7 +852,7 @@ fn create_hardcoded_rows( &partition_changed_action, &language_changed_action, &used_partition_array_refcell, - &do_used_part_check_refcell, + &subvol_partition_array_refcell, ); create_boot_row( &drive_mounts_adw_listbox, @@ -838,7 +861,7 @@ fn create_hardcoded_rows( &partition_changed_action, &language_changed_action, &used_partition_array_refcell, - &do_used_part_check_refcell, + &subvol_partition_array_refcell, ); create_root_row( &drive_mounts_adw_listbox, @@ -847,7 +870,7 @@ fn create_hardcoded_rows( &partition_changed_action, &language_changed_action, &used_partition_array_refcell, - &do_used_part_check_refcell, + &subvol_partition_array_refcell, ); drive_mounts_adw_listbox.append(&drive_mount_add_button); @@ -866,7 +889,7 @@ fn create_hardcoded_rows( #[strong] used_partition_array_refcell, #[strong] - do_used_part_check_refcell, + subvol_partition_array_refcell, move |_| { create_mount_row( &drive_mounts_adw_listbox, @@ -875,7 +898,7 @@ fn create_hardcoded_rows( &partition_changed_action, &language_changed_action, &used_partition_array_refcell, - &do_used_part_check_refcell, + &subvol_partition_array_refcell, ); } ));