Skip to content

Commit 6a9ffb5

Browse files
authored
fix: remove over uninstalls (#69)
1 parent 614f1c6 commit 6a9ffb5

File tree

21 files changed

+95
-38
lines changed

21 files changed

+95
-38
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ jobs:
211211
SIGN_SCRIPT_PATH="${GITHUB_WORKSPACE}/src-tauri/scripts/sign.ps1"
212212
sed -i.bak "s|\"sign.ps1\"|\"${SIGN_SCRIPT_PATH//\\/\/}\"|g" src-tauri/tauri.conf.json
213213
214+
- name: Code Analysis Core
215+
working-directory: ${{ github.workspace }}/core
216+
run: cargo clippy --all-targets --all-features -- -D warnings
217+
218+
- name: Code Analysis Tauri
219+
working-directory: ${{ github.workspace }}/src-tauri
220+
run: cargo clippy --all-targets --all-features -- -D warnings
221+
214222
- name: Build Release
215223
if: ${{ inputs.dry-run == false }}
216224
uses: tauri-apps/tauri-action@v0

core/.cargo/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
rustflags = [
3+
"-Dwarnings", # treat all warnings as errors
4+
"-Dunsafe_code", # deny unsafe blocks globally
5+
]

core/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dcl-launcher-core"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
edition = "2024"
55

66
[lib]
@@ -12,9 +12,11 @@ name = "dcl_launcher_core"
1212
path = "src/main.rs"
1313

1414
[profile.dev]
15+
overflow-checks = true
1516
incremental = true # Compile your binary in smaller steps.
1617

1718
[profile.release]
19+
overflow-checks = true
1820
codegen-units = 1 # Allows LLVM to perform better optimization.
1921
lto = true # Enables link-time-optimizations.
2022
opt-level = "s" # Prioritizes small binary size. Use `3` if you prefer speed.

core/src/analytics/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ impl Display for Event {
8686
Event::LAUNCH_CLIENT_START { .. } => "Launch Client Start",
8787
Event::LAUNCH_CLIENT_SUCCESS { .. } => "Launch Client Success",
8888
Event::LAUNCH_CLIENT_ERROR { .. } => "Launch Client Error",
89-
Event::LAUNCHER_UPDATE_CHECKING { .. } => "Launcher Update Checking",
89+
Event::LAUNCHER_UPDATE_CHECKING => "Launcher Update Checking",
9090
Event::LAUNCHER_UPDATE_AVAILABLE { .. } => "Launcher Update Available",
91-
Event::LAUNCHER_UPDATE_NOT_AVAILABLE { .. } => "Launcher Update Not Available",
91+
Event::LAUNCHER_UPDATE_NOT_AVAILABLE => "Launcher Update Not Available",
9292
Event::LAUNCHER_UPDATE_CANCELLED { .. } => "Launcher Update Cancelled",
9393
Event::LAUNCHER_UPDATE_ERROR { .. } => "Launcher Update Error",
9494
Event::LAUNCHER_UPDATE_DOWNLOADED { .. } => "Launcher Update Downloaded",

core/src/analytics/null_client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ impl NullClient {
1515
&self.session_id
1616
}
1717
}
18+
19+
impl Default for NullClient {
20+
fn default() -> Self {
21+
Self::new()
22+
}
23+
}

core/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl From<zip::result::ZipError> for StepError {
211211

212212
impl From<reqwest::Error> for StepError {
213213
fn from(value: reqwest::Error) -> Self {
214-
let url: Option<String> = value.url().map_or(None, |e| Some(e.as_str().to_owned()));
214+
let url: Option<String> = value.url().map(|e| e.as_str().to_owned());
215215
StepError::E2001_DOWNLOAD_FAILED { url, error: value }
216216
}
217217
}

core/src/flow.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use regex::Regex;
1414
use std::{path::PathBuf, sync::Arc};
1515
use tokio::sync::Mutex;
1616

17-
pub trait LaunchStep {
17+
trait LaunchStep {
1818
async fn is_complete(&self, state: Arc<Mutex<LaunchFlowState>>) -> Result<bool>;
1919

2020
fn start_label(&self) -> Result<Status>;
@@ -321,12 +321,9 @@ impl InstallStep {
321321
state: Arc<Mutex<LaunchFlowState>>,
322322
) -> Option<RecentDownload> {
323323
let mut guard = state.lock().await;
324-
let recent_download = guard.recent_download.clone();
325-
if recent_download.is_none() {
326-
return None;
327-
}
324+
let recent_download = guard.recent_download.clone()?;
328325
guard.recent_download = None;
329-
recent_download
326+
Some(recent_download)
330327
}
331328
}
332329

core/src/installs.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn get_explorer_bin_path(version: Option<&str>) -> Result<PathBuf> {
135135
Ok(base_path.join(EXPLORER_WIN_BIN_PATH))
136136
}
137137

138+
#[cfg(target_os = "macos")]
138139
fn move_recursive(src: &PathBuf, dst: &PathBuf) -> Result<()> {
139140
if !src.exists() {
140141
return Err(anyhow!("Source path does not exist"));
@@ -206,7 +207,7 @@ impl Eq for EntryVersion {}
206207

207208
impl PartialOrd for EntryVersion {
208209
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
209-
self.version.partial_cmp(&other.version)
210+
Some(self.cmp(other))
210211
}
211212
}
212213

@@ -248,10 +249,20 @@ async fn cleanup_versions() -> Result<()> {
248249
}
249250

250251
// Sort versions
251-
installations.sort_by(|a, b| a.cmp(b));
252+
installations.sort();
253+
254+
const KEEP_VERSIONS_AMOUNT: usize = 2;
255+
256+
if installations.len() <= KEEP_VERSIONS_AMOUNT {
257+
// Don't need to uninstall anything
258+
return Ok(());
259+
}
252260

253261
// Keep the latest 2 versions and delete the rest
254-
for version in installations.iter().take(installations.len() - 2) {
262+
for version in installations
263+
.iter()
264+
.take(installations.len() - KEEP_VERSIONS_AMOUNT)
265+
{
255266
let folder_path = explorer_path().join(version.to_restored());
256267
if folder_path.exists() {
257268
match fs::remove_dir_all(&folder_path) {
@@ -471,22 +482,22 @@ impl InstallsHub {
471482
const CHECK_INTERVAL: Duration = Duration::from_millis(100);
472483

473484
#[cfg(windows)]
474-
let GRACEFUL_EXIT_CODE: ExitStatus = std::process::ExitStatus::from_raw(0);
485+
let graceful_exit_code: ExitStatus = std::process::ExitStatus::from_raw(0);
475486

476487
#[cfg(unix)]
477-
let GRACEFUL_EXIT_CODE: ExitStatus = ExitStatus::from_raw(0 << 8); // exit code 0
488+
let graceful_exit_code: ExitStatus = ExitStatus::from_raw(0 << 8); // exit code 0
478489

479490
#[cfg(windows)]
480-
let STILL_ACTIVE_EXIT_CODE: ExitStatus = std::process::ExitStatus::from_raw(259);
491+
let still_active_exit_code: ExitStatus = std::process::ExitStatus::from_raw(259);
481492

482493
for _ in 0..(WAIT_TIMEOUT.as_millis() / CHECK_INTERVAL.as_millis()) {
483494
if let Some(exit_status) = child.try_wait()? {
484-
if exit_status == GRACEFUL_EXIT_CODE {
495+
if exit_status == graceful_exit_code {
485496
return Ok(());
486497
}
487498

488499
#[cfg(windows)]
489-
if exit_status == STILL_ACTIVE_EXIT_CODE {
500+
if exit_status == still_active_exit_code {
490501
break;
491502
}
492503

core/src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
2+
#![deny(
3+
clippy::unwrap_used,
4+
clippy::expect_used,
5+
clippy::panic,
6+
clippy::indexing_slicing,
7+
clippy::arithmetic_side_effects,
8+
clippy::todo,
9+
clippy::dbg_macro
10+
)]
11+
112
use anyhow::{Context, Ok, Result};
213
use dcl_launcher_core::{app::AppState, channel::EventChannel};
314
use log::info;
@@ -7,7 +18,7 @@ struct ConsoleChannel();
718
impl EventChannel for ConsoleChannel {
819
fn send(&self, status: dcl_launcher_core::types::Status) -> Result<()> {
920
let s = serde_json::to_string_pretty(&status)?;
10-
info!("{}", s);
21+
info!("{s}");
1122
Ok(())
1223
}
1324
}

0 commit comments

Comments
 (0)