fix some race conds

This commit is contained in:
Ward from fusion-voyager-3 2024-08-20 14:34:54 +00:00
parent a1ec14ed42
commit e4a605915d
5 changed files with 75 additions and 44 deletions

View File

@ -1,4 +1,4 @@
use std::{cell::{RefCell}, rc::Rc, sync::OnceLock};
use std::{cell::RefCell, rc::Rc, sync::OnceLock};
use adw::{prelude::*, subclass::prelude::*, *};
use glib::{clone, subclass::Signal, Properties};

View File

@ -26,6 +26,7 @@ impl DriveMountRow {
partition: create_parition_struct(&self.partition()),
mountpoint: self.mountpoint(),
mountopts: self.mountopts(),
used_by: self.id(),
}
}
}

View File

@ -216,9 +216,10 @@ pub fn create_efi_row(
} else {
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
}
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
)));
}
));
@ -241,8 +242,11 @@ pub fn create_efi_row(
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
),
));
}
),
);
@ -282,7 +286,6 @@ pub fn create_boot_row(
let null_checkbutton = gtk::CheckButton::builder().build();
for partition in partition_array {
let part_name = &partition.part_name.to_owned();
let partition_button = gtk::CheckButton::builder()
@ -445,9 +448,10 @@ pub fn create_boot_row(
} else {
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
}
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
)));
}
));
@ -470,8 +474,11 @@ pub fn create_boot_row(
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
),
));
}
),
);
@ -511,7 +518,6 @@ pub fn create_root_row(
let null_checkbutton = gtk::CheckButton::builder().build();
for partition in partition_array {
let part_name = &partition.part_name.to_owned();
let partition_button = gtk::CheckButton::builder()
@ -679,9 +685,10 @@ pub fn create_root_row(
} else {
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
}
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
)));
}
));
@ -704,8 +711,11 @@ pub fn create_root_row(
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
),
));
}
),
);
@ -746,7 +756,6 @@ pub fn create_mount_row(
let null_checkbutton = gtk::CheckButton::builder().build();
for partition in partition_array {
let part_name = &partition.part_name.to_owned();
let partition_button = gtk::CheckButton::builder()
@ -877,9 +886,10 @@ pub fn create_mount_row(
} else {
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
}
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
partition_changed_action.activate(Some(&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
)));
}
));
@ -902,8 +912,11 @@ pub fn create_mount_row(
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
));
&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
),
));
}
),
);
@ -966,14 +979,23 @@ fn post_check_drive_mount(
if partition_button.is_active() == true {
let part_name = &partition.part_name;
row.set_partition(part_name.to_string());
(*used_partition_array_refcell.borrow_mut())
.push(DriveMountRow::get_fstab_entry(&row));
if !used_partition_array_refcell
.borrow()
.iter()
.any(|e| part_name == &e.partition.part_name)
{
(*used_partition_array_refcell.borrow_mut())
.push(DriveMountRow::get_fstab_entry(&row));
}
} else {
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
}
partition_changed_action.activate(Some(
&glib::variant::Variant::from_data_with_type(row.id().to_string(), glib::VariantTy::STRING)
&glib::variant::Variant::from_data_with_type(
row.id().to_string(),
glib::VariantTy::STRING,
),
));
}
}
@ -1035,10 +1057,14 @@ fn post_check_drive_mount(
let used_partition_array = used_partition_array_refcell.borrow();
let subvol_partition_array = subvol_partition_array_refcell.borrow();
let action_id = String::from_utf8_lossy(varient.unwrap().data()).parse::<i32>().unwrap();
//dbg!(&used_partition_array);
let action_id = String::from_utf8_lossy(varient.unwrap().data())
.parse::<i32>()
.unwrap();
if used_partition_array.iter().any(|e| {
(part_name == &e.partition.part_name)
(part_name == &e.partition.part_name && part_name != &row.partition())
&& (subvol_partition_array.iter().any(|e| part_name == e))
}) {
if *partition_row_struct.never.borrow() == false
@ -1050,21 +1076,22 @@ fn post_check_drive_mount(
(*partition_row_struct.used.borrow_mut()) = 2;
} else if used_partition_array
.iter()
.any(|e| part_name == &e.partition.part_name)
.any(|e| part_name == &e.partition.part_name && e.used_by != row.id() && !subvol_partition_array.iter().any(|e| part_name == e))
{
if action_id != row.id() {
if &row.partition() == part_name {
null_checkbutton.set_active(true);
partition_row_struct.widget.set_sensitive(false);
row.set_partition("");
}
partition_row_struct.widget.set_sensitive(false);
(*partition_row_struct.used.borrow_mut()) = 1;
} else {
if *partition_row_struct.never.borrow() == false
&& *partition_row_struct.swap_fs_error.borrow() == false
&& *partition_row_struct.hardcode_fs_error.borrow() == false
{
partition_row_struct.widget.set_sensitive(true);
}
(*partition_row_struct.used.borrow_mut()) = 0;
if *partition_row_struct.never.borrow() == false
&& *partition_row_struct.swap_fs_error.borrow() == false
&& *partition_row_struct.hardcode_fs_error.borrow() == false
{
partition_row_struct.widget.set_sensitive(true);
}
(*partition_row_struct.used.borrow_mut()) = 0;
}
}
));

View File

@ -32,11 +32,12 @@ pub fn manual_partitioning_page(
let partition_array_refcell = Rc::new(RefCell::new(get_partitions()));
let used_partition_array_refcell: Rc<RefCell<Vec<FstabEntry>>> = Rc::new(RefCell::default());
let subvol_partition_array_refcell: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::default());
let extra_mount_id_refcell: Rc<RefCell<i32>> = Rc::new(RefCell::default());
let extra_mount_id_refcell: Rc<RefCell<i32>> = Rc::new(RefCell::new(3));
//
let partition_changed_action = gio::SimpleAction::new("partition-changed", Some(glib::VariantTy::STRING));
let partition_changed_action =
gio::SimpleAction::new("partition-changed", Some(glib::VariantTy::STRING));
//
@ -73,7 +74,7 @@ pub fn manual_partitioning_page(
&language_changed_action,
&used_partition_array_refcell,
&subvol_partition_array_refcell,
&extra_mount_id_refcell
&extra_mount_id_refcell,
);
let open_disk_utility_button = gtk::Button::builder()
@ -167,6 +168,7 @@ pub fn manual_partitioning_page(
(*partition_method_manual_crypttab_entry_array_refcell.borrow_mut()) = Vec::new();
(*used_partition_array_refcell.borrow_mut()) = Vec::new();
(*subvol_partition_array_refcell.borrow_mut()) = Vec::new();
(*extra_mount_id_refcell.borrow_mut()) = 3;
create_hardcoded_rows(
&drive_mounts_adw_listbox,
&drive_rows_size_group,
@ -175,7 +177,7 @@ pub fn manual_partitioning_page(
&language_changed_action,
&used_partition_array_refcell,
&subvol_partition_array_refcell,
&extra_mount_id_refcell
&extra_mount_id_refcell,
);
}
));
@ -498,7 +500,7 @@ fn create_hardcoded_rows(
&language_changed_action,
&used_partition_array_refcell,
&subvol_partition_array_refcell,
&extra_mount_id_refcell
&extra_mount_id_refcell,
);
}
));

View File

@ -191,6 +191,7 @@ pub struct FstabEntry {
pub partition: Partition,
pub mountpoint: String,
pub mountopts: String,
pub used_by: i32,
}
#[derive(Default, Clone, Debug)]