From c34958f25674777efde3de0bbac8bdde49f86bfc Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Tue, 20 Aug 2024 23:57:29 +0300 Subject: [PATCH] Fix small annoynce with subvols --- src/manual_partitioning_page/func.rs | 56 ++++++++++++++++++---------- src/manual_partitioning_page/mod.rs | 6 +-- src/partitioning_page/mod.rs | 5 +++ 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/manual_partitioning_page/func.rs b/src/manual_partitioning_page/func.rs index 29cc27b..df2b273 100644 --- a/src/manual_partitioning_page/func.rs +++ b/src/manual_partitioning_page/func.rs @@ -1,6 +1,6 @@ use crate::drive_mount_row::DriveMountRow; use crate::installer_stack_page; -use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition}; +use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition, SubvolDeclaration}; use adw::gio; use adw::prelude::*; use glib::{clone, closure_local, ffi::gboolean}; @@ -27,7 +27,7 @@ pub fn create_efi_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - subvol_partition_array_refcell: &Rc>>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -90,7 +90,7 @@ pub fn create_efi_row( && (subvol_partition_array_refcell .borrow() .iter() - .any(|e| part_name == e)) + .any(|e| *e.part_name.borrow() == *part_name)) }) { PartitionRow { @@ -212,9 +212,13 @@ pub fn create_efi_row( row, move |_| { if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") { - (*subvol_partition_array_refcell.borrow_mut()).push(row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).push(SubvolDeclaration{ + part_name: Rc::new(RefCell::new(row.partition())), + made_by: Rc::new(RefCell::new(row.id())) + } + ); } else { - (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).retain(|x| *x.made_by.borrow() != row.id()); } partition_changed_action.activate(None); } @@ -250,7 +254,7 @@ pub fn create_boot_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - subvol_partition_array_refcell: &Rc>>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -313,7 +317,7 @@ pub fn create_boot_row( && (subvol_partition_array_refcell .borrow() .iter() - .any(|e| part_name == e)) + .any(|e| *e.part_name.borrow() == *part_name)) }) { PartitionRow { @@ -435,9 +439,13 @@ pub fn create_boot_row( row, move |_| { if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") { - (*subvol_partition_array_refcell.borrow_mut()).push(row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).push(SubvolDeclaration{ + part_name: Rc::new(RefCell::new(row.partition())), + made_by: Rc::new(RefCell::new(row.id())) + } + ); } else { - (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).retain(|x| *x.made_by.borrow() != row.id()); } partition_changed_action.activate(None); } @@ -473,7 +481,7 @@ pub fn create_root_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - subvol_partition_array_refcell: &Rc>>, + subvol_partition_array_refcell: &Rc>>, ) { let partition_scroll_child = gtk::ListBox::builder() .selection_mode(gtk::SelectionMode::None) @@ -536,7 +544,7 @@ pub fn create_root_row( && (subvol_partition_array_refcell .borrow() .iter() - .any(|e| part_name == e)) + .any(|e| *e.part_name.borrow() == *part_name)) }) { PartitionRow { @@ -663,9 +671,13 @@ pub fn create_root_row( row, move |_| { if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") { - (*subvol_partition_array_refcell.borrow_mut()).push(row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).push(SubvolDeclaration{ + part_name: Rc::new(RefCell::new(row.partition())), + made_by: Rc::new(RefCell::new(row.id())) + } + ); } else { - (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).retain(|x| *x.made_by.borrow() != row.id()); } partition_changed_action.activate(None); } @@ -701,7 +713,7 @@ pub fn create_mount_row( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - subvol_partition_array_refcell: &Rc>>, + subvol_partition_array_refcell: &Rc>>, extra_mount_id_refcell: &Rc>, ) { let partition_scroll_child = gtk::ListBox::builder() @@ -765,7 +777,7 @@ pub fn create_mount_row( && (subvol_partition_array_refcell .borrow() .iter() - .any(|e| part_name == e)) + .any(|e| *e.part_name.borrow() == *part_name)) }) { PartitionRow { @@ -855,9 +867,13 @@ pub fn create_mount_row( row, move |_| { if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") { - (*subvol_partition_array_refcell.borrow_mut()).push(row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).push(SubvolDeclaration{ + part_name: Rc::new(RefCell::new(row.partition())), + made_by: Rc::new(RefCell::new(row.id())) + } + ); } else { - (*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition()); + (*subvol_partition_array_refcell.borrow_mut()).retain(|x| *x.made_by.borrow() != row.id()); } partition_changed_action.activate(None); } @@ -894,7 +910,7 @@ fn post_check_drive_mount( partition_changed_action: &gio::SimpleAction, partition: &Partition, used_partition_array_refcell: &Rc>>, - subvol_partition_array_refcell: &Rc>>, + subvol_partition_array_refcell: &Rc>>, ) { partition_row_struct.widget.add_prefix(partition_button); partition_button.connect_toggled(clone!( @@ -1027,7 +1043,7 @@ fn post_check_drive_mount( if used_partition_array.iter().any(|e| { (part_name == &e.partition.part_name && part_name != &row.partition()) - && (subvol_partition_array.iter().any(|e| part_name == e)) + && (subvol_partition_array.iter().any(|e| *e.part_name.borrow() == *part_name)) }) { if *partition_row_struct.never.borrow() == false && *partition_row_struct.swap_fs_error.borrow() == false @@ -1039,7 +1055,7 @@ fn post_check_drive_mount( } else if used_partition_array.iter().any(|e| { part_name == &e.partition.part_name && e.used_by != row.id() - && !subvol_partition_array.iter().any(|e| part_name == e) + && !subvol_partition_array.iter().any(|e| *e.part_name.borrow() == *part_name) }) { if &row.partition() == part_name { null_checkbutton.set_active(true); diff --git a/src/manual_partitioning_page/mod.rs b/src/manual_partitioning_page/mod.rs index b3f6505..f63fade 100644 --- a/src/manual_partitioning_page/mod.rs +++ b/src/manual_partitioning_page/mod.rs @@ -2,7 +2,7 @@ use crate::drive_mount_row::DriveMountRow; use crate::installer_stack_page; use crate::partitioning_page; use crate::partitioning_page::get_luks_uuid; -use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition}; +use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition, SubvolDeclaration}; use adw::gio; use adw::prelude::*; use glib::{clone, closure_local, ffi::gboolean}; @@ -33,7 +33,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 subvol_partition_array_refcell: Rc>> = Rc::new(RefCell::default()); + let subvol_partition_array_refcell: Rc>> = Rc::new(RefCell::default()); let extra_mount_id_refcell: Rc> = Rc::new(RefCell::new(3)); // @@ -391,7 +391,7 @@ fn create_hardcoded_rows( partition_changed_action: &gio::SimpleAction, language_changed_action: &gio::SimpleAction, used_partition_array_refcell: &Rc>>, - subvol_partition_array_refcell: &Rc>>, + subvol_partition_array_refcell: &Rc>>, extra_mount_id_refcell: &Rc>, ) { let drive_mount_add_button_icon = gtk::Image::builder() diff --git a/src/partitioning_page/mod.rs b/src/partitioning_page/mod.rs index 2724c6b..5119b81 100644 --- a/src/partitioning_page/mod.rs +++ b/src/partitioning_page/mod.rs @@ -202,6 +202,11 @@ pub struct CrypttabEntry { pub password: Option, } +pub struct SubvolDeclaration { + pub part_name: Rc>, + pub made_by: Rc>, +} + pub fn get_block_devices() -> Vec { let mut block_devices = Vec::new();