Skip to content

Commit 2a608f1

Browse files
committed
Merge branch 'minor-refactor'
2 parents 3ab0e61 + 67d8599 commit 2a608f1

18 files changed

Lines changed: 153 additions & 184 deletions

File tree

android/translations-converter/src/main.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -406,25 +406,26 @@ fn generate_translations(
406406

407407
for translation in translations {
408408
match translation.value {
409-
MsgValue::Invariant(translation_value, arg_ordering) => {
410-
if let Some(android_key) = known_strings.remove(&translation.id.normalize()) {
411-
localized_strings.push(StringResource::new(
412-
android_key.name,
413-
&translation_value.normalize(),
414-
arg_ordering.as_ref(),
415-
));
416-
}
409+
MsgValue::Invariant(translation_value, arg_ordering)
410+
if let Some(android_key) = known_strings.remove(&translation.id.normalize()) =>
411+
{
412+
localized_strings.push(StringResource::new(
413+
android_key.name,
414+
&translation_value.normalize(),
415+
arg_ordering.as_ref(),
416+
));
417417
}
418-
MsgValue::Plural { values, .. } => {
419-
if let Some(android_key) = known_plurals.remove(&translation.id.normalize()) {
420-
let values = values.into_iter().map(|message| message.normalize());
421-
422-
localized_plurals.push(PluralResource::new(
423-
android_key.name.clone(),
424-
plural_quantities.clone().zip(values),
425-
));
426-
}
418+
MsgValue::Plural { values, .. }
419+
if let Some(android_key) = known_plurals.remove(&translation.id.normalize()) =>
420+
{
421+
let values = values.into_iter().map(|message| message.normalize());
422+
423+
localized_plurals.push(PluralResource::new(
424+
android_key.name.clone(),
425+
plural_quantities.clone().zip(values),
426+
));
427427
}
428+
_ => {}
428429
}
429430
}
430431

installer-downloader/src/controller.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ pub fn initialize_controller<T: AppDelegate + 'static>(delegate: &mut T, environ
5858
let platform = MetaRepositoryPlatform::current().expect("current platform must be supported");
5959
let version_provider = HttpVersionInfoProvider::from(platform);
6060

61-
#[cfg(target_os = "windows")]
62-
type CacheDir = mullvad_update::local::AppCacheDir;
63-
64-
#[cfg(target_os = "macos")]
65-
type CacheDir = mullvad_update::local::NoopAppCacheDir;
61+
type CacheDir = cfg_select! {
62+
target_os = "windows" => { mullvad_update::local::AppCacheDir }
63+
target_os = "macos" => { mullvad_update::local::NoopAppCacheDir }
64+
};
6665

6766
AppController::initialize::<_, Downloader<T>, CacheDir, DirProvider>(
6867
delegate,

installer-downloader/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ mod inner {
2424
.expect("failed to create tokio runtime");
2525
let _guard = rt.enter();
2626

27-
#[cfg(target_os = "windows")]
28-
super::winapi_impl::main();
29-
30-
#[cfg(target_os = "macos")]
31-
super::cacao_impl::main();
27+
cfg_select! {
28+
target_os = "windows" => { super::winapi_impl::main(); }
29+
target_os = "macos" => { super::cacao_impl::main(); }
30+
}
3231
}
3332
}
3433

installer-downloader/src/temp.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,9 @@ pub struct TempDirProvider;
3838
impl DirectoryProvider for TempDirProvider {
3939
/// Create a locked-down directory to store downloads in
4040
async fn create_download_dir() -> anyhow::Result<PathBuf> {
41-
#[cfg(windows)]
42-
{
43-
admin_temp_dir().await
44-
}
45-
46-
#[cfg(target_os = "macos")]
47-
{
48-
temp_dir().await
41+
cfg_select! {
42+
windows => { admin_temp_dir().await }
43+
target_os = "macos" => { temp_dir().await }
4944
}
5045
}
5146
}

mullvad-api/src/rest.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,12 @@ impl Error {
100100
/// Return true if there was no route to the destination
101101
pub fn is_offline(&self) -> bool {
102102
match self {
103-
Error::LegacyHyperError(error) if error.is_connect() => {
104-
if let Some(cause) = error.source()
105-
&& let Some(err) = cause.downcast_ref::<std::io::Error>()
106-
{
107-
return err.raw_os_error() == Some(libc::ENETUNREACH);
108-
}
109-
110-
false
103+
Error::LegacyHyperError(error)
104+
if error.is_connect()
105+
&& let Some(cause) = error.source()
106+
&& let Some(err) = cause.downcast_ref::<std::io::Error>() =>
107+
{
108+
err.raw_os_error() == Some(libc::ENETUNREACH)
111109
}
112110
// TODO: Currently, we use the legacy hyper client for all REST requests. If this
113111
// changes in the future, we likely need to match on `Error::HyperError` here and

mullvad-daemon/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ fn main() {
4242

4343
if matches!(target_os(), Os::Macos) {
4444
// Set the minimum version of macOS on which mullvad-daemon can run.
45-
if cfg!(target_arch = "x86_64") {
46-
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.12");
47-
} else if cfg!(target_arch = "aarch64") {
48-
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=11.0");
45+
cfg_select! {
46+
target_arch = "x86_64" => { println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.12"); }
47+
target_arch = "aarch64" => { println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=11.0"); }
48+
_ => {}
4949
}
5050
}
5151
}

mullvad-daemon/src/account_history.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ impl AccountHistory {
3939
current_number: Option<AccountNumber>,
4040
) -> Result<AccountHistory> {
4141
let mut options = fs::OpenOptions::new();
42-
#[cfg(unix)]
43-
{
44-
options.mode(0o600);
45-
}
46-
#[cfg(windows)]
47-
{
48-
// a share mode of zero ensures exclusive access to the file to *this* process
49-
options.share_mode(0);
42+
cfg_select! {
43+
unix => { options.mode(0o600); }
44+
windows => {
45+
// a share mode of zero ensures exclusive access to the file to *this* process
46+
options.share_mode(0);
47+
}
48+
_ => {}
5049
}
5150

5251
let path = settings_dir.join(ACCOUNT_HISTORY_FILE);

mullvad-daemon/src/cleanup.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,38 @@ async fn clear_cache_directory() -> Result<(), Error> {
4444
}
4545

4646
async fn clear_directory(path: &Path) -> Result<(), Error> {
47-
#[cfg(not(target_os = "windows"))]
48-
{
49-
fs::remove_dir_all(path)
50-
.await
51-
.map_err(|e| Error::RemoveDir(path.display().to_string(), e))?;
52-
fs::create_dir_all(path)
53-
.await
54-
.map_err(|e| Error::CreateDir(path.display().to_string(), e))
55-
}
56-
#[cfg(target_os = "windows")]
57-
{
58-
let mut dir = fs::read_dir(&path).await.map_err(Error::ReadDir)?;
47+
cfg_select! {
48+
target_os = "windows" => {
49+
let mut dir = fs::read_dir(&path).await.map_err(Error::ReadDir)?;
5950

60-
let mut result = Ok(());
51+
let mut result = Ok(());
6152

62-
while let Some(entry) = dir.next_entry().await.map_err(Error::FileEntry)? {
63-
let entry_type = match entry.file_type().await {
64-
Ok(entry_type) => entry_type,
65-
Err(error) => {
66-
result = result.and(Err(Error::FileType(error)));
67-
continue;
68-
}
69-
};
53+
while let Some(entry) = dir.next_entry().await.map_err(Error::FileEntry)? {
54+
let entry_type = match entry.file_type().await {
55+
Ok(entry_type) => entry_type,
56+
Err(error) => {
57+
result = result.and(Err(Error::FileType(error)));
58+
continue;
59+
}
60+
};
7061

71-
let removal = if entry_type.is_file() || entry_type.is_symlink() {
72-
fs::remove_file(entry.path()).await
73-
} else {
74-
fs::remove_dir_all(entry.path()).await
75-
};
76-
result = result
77-
.and(removal.map_err(|e| Error::RemoveDir(entry.path().display().to_string(), e)));
62+
let removal = if entry_type.is_file() || entry_type.is_symlink() {
63+
fs::remove_file(entry.path()).await
64+
} else {
65+
fs::remove_dir_all(entry.path()).await
66+
};
67+
result = result
68+
.and(removal.map_err(|e| Error::RemoveDir(entry.path().display().to_string(), e)));
69+
}
70+
result
71+
}
72+
_ => {
73+
fs::remove_dir_all(path)
74+
.await
75+
.map_err(|e| Error::RemoveDir(path.display().to_string(), e))?;
76+
fs::create_dir_all(path)
77+
.await
78+
.map_err(|e| Error::CreateDir(path.display().to_string(), e))
7879
}
79-
result
8080
}
8181
}

mullvad-daemon/src/management_interface.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,11 +1412,10 @@ impl ManagementInterfaceServer {
14121412
Err(timeout) => {
14131413
log::error!("Timed out while shutting down management server: {timeout}");
14141414
}
1415-
Ok(join_result) => {
1416-
if let Err(_error) = join_result {
1417-
log::error!("Management server task failed to execute until completion");
1418-
}
1415+
Ok(join_result) if let Err(_error) = &join_result => {
1416+
log::error!("Management server task failed to execute until completion");
14191417
}
1418+
Ok(_) => {}
14201419
}
14211420
}
14221421

mullvad-leak-checker/src/util.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,13 @@ pub fn get_interface_ip(interface: &Interface, ip_version: Ip) -> anyhow::Result
7171
};
7272

7373
match ip_version {
74-
Ip::V4(()) => {
75-
if let Some(address) = address.as_sockaddr_in() {
76-
return Ok(IpAddr::V4(address.ip()));
77-
};
74+
Ip::V4(()) if let Some(address) = address.as_sockaddr_in() => {
75+
return Ok(IpAddr::V4(address.ip()));
7876
}
79-
Ip::V6(()) => {
80-
if let Some(address) = address.as_sockaddr_in6() {
81-
return Ok(IpAddr::V6(address.ip()));
82-
};
77+
Ip::V6(()) if let Some(address) = address.as_sockaddr_in6() => {
78+
return Ok(IpAddr::V6(address.ip()));
8379
}
80+
_ => {}
8481
}
8582
}
8683

0 commit comments

Comments
 (0)