diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-09-01 14:08:08 +0200 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-09-30 09:51:49 +0200 |
| commit | 2a9fa6f391e2e734af608eb93440c2f21fca6819 (patch) | |
| tree | 8ec25f7e285ea649fbdfc0a78aa6f4aa78260be3 | |
| parent | d6aa77cfa6b882e6b97c37ddaf8279e1cd5faa0a (diff) | |
| download | mullvadvpn-2a9fa6f391e2e734af608eb93440c2f21fca6819.tar.xz mullvadvpn-2a9fa6f391e2e734af608eb93440c2f21fca6819.zip | |
Verify that an access method has a unique name before updating
| -rw-r--r-- | mullvad-types/src/access_method.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/mullvad-types/src/access_method.rs b/mullvad-types/src/access_method.rs index 12040bf4c1..342b8ffcaf 100644 --- a/mullvad-types/src/access_method.rs +++ b/mullvad-types/src/access_method.rs @@ -71,15 +71,26 @@ impl Settings { &mut self, predicate: impl Fn(&AccessMethodSetting) -> bool, f: impl FnOnce(&mut AccessMethodSetting), - ) -> bool { + ) -> Result<bool, Error> { let mut updated = false; + + let handle = self.clone(); + let update_check = |new_access_method| { + handle.check_custom_access_method_name_is_unique(new_access_method)?; + Ok(()) + }; + if let Some(access_method) = self.iter_mut().find(|setting| predicate(setting)) { - f(access_method); + let mut new_access_method = access_method.clone(); + f(&mut new_access_method); + update_check(&new_access_method)?; + *access_method = new_access_method; + updated = true; } self.ensure_consistent_state(); - updated + Ok(updated) } /// Remove all custom access methods. |
