From 94c1d0ecdcae1ffcab6898e7ee845e3e3bdcfefe Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 11:54:41 +0800 Subject: [PATCH 01/27] Implement logic for CleanWorkflow --- src/workflows/clean.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/workflows/clean.rs b/src/workflows/clean.rs index dda4479..3d2553c 100644 --- a/src/workflows/clean.rs +++ b/src/workflows/clean.rs @@ -1,12 +1,38 @@ -use crate::{BeansError, RunnerContext}; +use log::{info, warn}; +use crate::{BeansError, helper, RunnerContext}; #[derive(Debug, Clone)] pub struct CleanWorkflow { pub context: RunnerContext } impl CleanWorkflow { - pub async fn wizard(_ctx: &mut RunnerContext) -> Result<(), BeansError> + pub fn wizard(_ctx: &mut RunnerContext) -> Result<(), BeansError> { - todo!("please implement. clean action deletes temporary files") + let target_directory = helper::get_tmp_dir(); + + info!("[CleanWorkflow] Cleaning up {}", target_directory); + if helper::file_exists(target_directory.clone()) == false { + warn!("[CleanWorkflow] Temporary directory not found, nothing to clean.") + } + + + // delete directory and it's contents (and error handling) + if let Err(e) = std::fs::remove_dir_all(&target_directory) { + return Err(BeansError::CleanTempFailure { + location: target_directory, + error: e + }); + } + + // re-creating the temporary directory (and error handling) + if let Err(e) = std::fs::create_dir(&target_directory) { + return Err(BeansError::DirectoryCreateFailure { + location: target_directory, + error: e + }); + } + + info!("[CleanWorkflow] Done!"); + return Ok(()); } } \ No newline at end of file From a00b6ce19e54e7f395a5443ca7130bee50c1e3b3 Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 11:54:54 +0800 Subject: [PATCH 02/27] Updated error.rs --- src/error.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/error.rs b/src/error.rs index 85f0e38..f67ecf2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -26,6 +26,11 @@ pub enum BeansError location: String, error: std::io::Error }, + #[error("Failed to create directory {location} ({error:})")] + DirectoryCreateFailure { + location: String, + error: std::io::Error + }, #[error("Failed to extract {src_file} to directory {target_dir} ({error:})")] TarExtractFailure { src_file: String, @@ -154,6 +159,12 @@ pub enum BeansError #[error("Failed to backup gameinfo.txt, {reason:}")] GameinfoBackupFailure { reason: GameinfoBackupFailureReason + }, + + #[error("Failed to remove files in {location} ({error:})")] + CleanTempFailure { + location: String, + error: std::io::Error } } #[derive(Debug)] From ce4ff93273d2b000cab818197dafb7f5f63abdb0 Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 11:55:59 +0800 Subject: [PATCH 03/27] Add sub-command for CleanWorkflow --- src/main.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d609842..158bd83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use beans_rs::{flags, helper, PANIC_MSG_CONTENT, RunnerContext, wizard}; use beans_rs::flags::LaunchFlag; use beans_rs::helper::parse_location; use beans_rs::SourceModDirectoryParam; -use beans_rs::workflows::{InstallWorkflow, UpdateWorkflow, VerifyWorkflow}; +use beans_rs::workflows::{CleanWorkflow, InstallWorkflow, UpdateWorkflow, VerifyWorkflow}; pub const DEFAULT_LOG_LEVEL_RELEASE: LevelFilter = LevelFilter::Info; #[cfg(debug_assertions)] @@ -156,6 +156,8 @@ impl Launcher .subcommand(Command::new("update") .about("Update your installation") .arg(Launcher::create_location_arg())) + .subcommand(Command::new("clean-tmp") + .about("Clean up temporary files used by beans")) .args([ Arg::new("debug") .long("debug") @@ -243,6 +245,9 @@ impl Launcher self.to_location = Launcher::find_arg_sourcemods_location(wz_matches); self.task_wizard().await; }, + Some(("clean-tmp", _)) => { + self.task_clean_tmp().await; + }, _ => { self.task_wizard().await; } @@ -371,6 +376,20 @@ impl Launcher } } + /// Handler for the `clean-tmp` subcommand. + /// + /// NOTE this function uses `panic!` when `CleanWorkflow::wizard` fails. panics are handled + /// and are reported via sentry. + pub async fn task_clean_tmp(&mut self) + { + let mut ctx = self.try_create_context().await; + if let Err(e) = CleanWorkflow::wizard(&mut ctx) { + panic!("Failed to run CleanWorkflow {:#?}", e); + } else { + logic_done(); + } + } + /// try and create an instance of `RunnerContext` via the `create_auto` method while setting /// the `sml_via` parameter to the output of `self.try_get_smdp()` /// From 52232f1abb163a867254d9e5a8e0b8a52e2c9515 Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 11:56:06 +0800 Subject: [PATCH 04/27] Add wizard option for CleanWorkflow --- src/wizard.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wizard.rs b/src/wizard.rs index 2f5ba01..aa2a162 100644 --- a/src/wizard.rs +++ b/src/wizard.rs @@ -4,7 +4,7 @@ use async_recursion::async_recursion; use log::{debug, error, info, trace}; use std::backtrace::Backtrace; use crate::flags::LaunchFlag; -use crate::workflows::{InstallWorkflow, UpdateWorkflow, VerifyWorkflow}; +use crate::workflows::{CleanWorkflow, InstallWorkflow, UpdateWorkflow, VerifyWorkflow}; #[derive(Debug, Clone)] pub struct WizardContext @@ -82,14 +82,18 @@ impl WizardContext println!("1 - Install or reinstall the game"); println!("2 - Check for and apply any available updates"); println!("3 - Verify and repair game files"); + println!("c - Clean up temporary files used by beans."); println!(); println!("q - Quit"); let user_input = helper::get_input("-- Enter option below --"); match user_input.to_lowercase().as_str() { - "1" => WizardContext::menu_error_catch(self.task_install().await), - "2" => WizardContext::menu_error_catch(self.task_update().await), - "3" => WizardContext::menu_error_catch(self.task_verify().await), - "d" => { + "1" | "install" => WizardContext::menu_error_catch(self.task_install().await), + "2" | "update" => WizardContext::menu_error_catch(self.task_update().await), + "3" | "verify" => WizardContext::menu_error_catch(self.task_verify().await), + "c" | "clean" => { + Self::menu_error_catch(CleanWorkflow::wizard(&mut self.context)) + }, + "d" | "debug" => { flags::add_flag(LaunchFlag::DEBUG_MODE); info!("Debug mode enabled!"); self.menu().await; From f76c26508b2ed4d4c0cd0760f581b9dd05b63abb Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 12:53:44 +0800 Subject: [PATCH 05/27] Add PROMPT_DO_WHATEVER --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1fd11c0..77e85ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,8 @@ pub const PANIC_MSG_CONTENT: &str = include_str!("text/msgbox_panic_text.txt"); /// /// just like the `pause` thing in batch. pub static mut PAUSE_ONCE_DONE: bool = false; +/// When `true`, everything that prompts the user for Y/N should use the default option. +pub static mut PROMPT_DO_WHATEVER: bool = false; // ------------------------------------------------------------------------ From 932193bca40886b3634e9177938e42a9a0195b65 Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 12:54:54 +0800 Subject: [PATCH 06/27] Add argument --confirm --- src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 158bd83..45ef310 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,6 +130,14 @@ impl Launcher .help("Manually specify sourcemods directory. When not provided, beans-rs will automatically detect the sourcemods directory.") .required(false) } + fn create_confirm_arg() -> Arg + { + Arg::new("confirm") + .long("confirm") + .help("When prompted to do something (as a multi-choice option), the default option will be automatically chosen when this switch is provided, and there is a default multi-choice option available.") + .required(false) + .action(ArgAction::SetTrue) + } pub async fn run() { let cmd = Command::new("beans-rs") @@ -149,7 +157,8 @@ impl Launcher Arg::new("target-version") .long("target-version") .help("Specify the version to install. Ignored when [--from] is used.") - .required(false)])) + .required(false), + Self::create_confirm_arg()])) .subcommand(Command::new("verify") .about("Verify your current installation") .arg(Launcher::create_location_arg())) @@ -171,7 +180,8 @@ impl Launcher .long("no-pause") .help("When provided, beans-rs will not wait for user input before exiting. It is suggested that server owners use this for any of their scripts.") .action(ArgAction::SetTrue), - Launcher::create_location_arg() + Self::create_location_arg(), + Self::create_confirm_arg() ]); let mut i = Self::new(&cmd.get_matches()); @@ -190,6 +200,7 @@ impl Launcher }; i.set_debug(); i.set_no_pause(); + i.set_prompt_do_whatever(); i.to_location = Launcher::find_arg_sourcemods_location(&i.root_matches); return i; @@ -254,6 +265,15 @@ impl Launcher } } + pub fn set_prompt_do_whatever(&mut self) + { + if self.root_matches.get_flag("confirm") { + unsafe { + beans_rs::PROMPT_DO_WHATEVER = true; + } + } + } + /// Try and get `SourceModDirectoryParam`. /// Returns SourceModDirectoryParam::default() when `to_location` is `None`. fn try_get_smdp(&mut self) -> SourceModDirectoryParam @@ -284,6 +304,12 @@ impl Launcher pub async fn task_install(&mut self, matches: &ArgMatches) { self.to_location = Launcher::find_arg_sourcemods_location(&matches); + if matches.get_flag("confirm") { + unsafe { + beans_rs::PROMPT_DO_WHATEVER = true; + } + } + let mut ctx = self.try_create_context().await; // call install_version when target-version is found. From 3e783c145ab55a60dd05fdf19740b54755438bde Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 12:55:39 +0800 Subject: [PATCH 07/27] Add function prompt_confirm --- src/workflows/install.rs | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/workflows/install.rs b/src/workflows/install.rs index b5177d4..d7953ac 100644 --- a/src/workflows/install.rs +++ b/src/workflows/install.rs @@ -1,5 +1,6 @@ -use log::{debug, error, warn}; +use log::{debug, error, info, warn}; use crate::{DownloadFailureReason, helper, RunnerContext}; +use crate::appvar::AppVarData; use crate::BeansError; use crate::version::{AdastralVersionFile, RemoteVersion}; @@ -18,6 +19,44 @@ impl InstallWorkflow { Self::install_with_remote_version(ctx, latest_remote_id, latest_remote).await } + /// Prompt the user to confirm if they want to reinstall (when parameter `current_version` is Some) + /// + /// Will always return `true` when `crate::PROMPT_DO_WHATEVER` is `true`. + /// + /// Returns: `true` when the installation should continue, `false` when we should silently abort. + pub fn prompt_confirm(current_version: Option) -> bool + { + unsafe { + if crate::PROMPT_DO_WHATEVER { + info!("[InstallWorkflow::prompt_confirm] skipping since PROMPT_DO_WHATEVER is true"); + return true; + } + } + let av = AppVarData::get(); + if let Some(v) = current_version { + println!("[InstallWorkflow::prompt_confirm] Seems like {} is already installed (v{})", v, av.mod_info.name_stylized); + + println!("Are you sure that you want to reinstall?"); + println!("Yes/Y (default)"); + println!("No/N"); + let user_input = helper::get_input("-- Enter option below --"); + match user_input.to_lowercase().as_str() { + "y" | "yes" | "" => { + true + }, + "n" | "no" => { + false + }, + _ => { + println!("Unknown option \"{}\"", user_input.to_lowercase()); + Self::prompt_confirm(current_version) + } + } + } else { + true + } + } + /// Install the specified version by its ID to the output directory. pub async fn install_version(&mut self, version_id: usize) -> Result<(), BeansError> { From 9cc2d592de896249334520f74906198a3661c7e3 Mon Sep 17 00:00:00 2001 From: kate Date: Tue, 25 Jun 2024 12:56:54 +0800 Subject: [PATCH 08/27] Call prompt_confirm in install_with_remote_version --- src/workflows/install.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/workflows/install.rs b/src/workflows/install.rs index d7953ac..adf030b 100644 --- a/src/workflows/install.rs +++ b/src/workflows/install.rs @@ -73,9 +73,18 @@ impl InstallWorkflow { InstallWorkflow::install_with_remote_version(&mut ctx, version_id, target_version.clone()).await } + /// Install with a specific remote version. + /// + /// Note: Will call Self::prompt_confirm, so set `crate::PROMPT_DO_WHATEVER` to `true` before you call + /// this function if you don't want to wait for a newline from stdin. pub async fn install_with_remote_version(ctx: &mut RunnerContext, version_id: usize, version: RemoteVersion) -> Result<(), BeansError> { + if Self::prompt_confirm(ctx.current_version) == false { + info!("[InstallWorkflow] Operation aborted by user"); + return Ok(()); + } + println!("{:=>60}\nInstalling version {} to {}\n{0:=>60}", "=", version_id, &ctx.sourcemod_path); let presz_loc = RunnerContext::download_package(version).await?; Self::install_from(presz_loc.clone(), ctx.sourcemod_path.clone(), Some(version_id)).await?; From cfcc3cf90c60c6a84911148ffcf956cde131853b Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:10:30 +0000 Subject: [PATCH 09/27] Use ubuntu-20.04 instead of ubuntu-latest --- .github/workflows/compile.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index ed79325..8a66c5e 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest + - os: ubuntu-20.04 filename: 'beans-rs' - os: windows-latest filename: 'beans-rs.exe' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 62508a3..133ed30 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest + - os: ubuntu-20.04 filename: 'beans-rs' - os: windows-latest filename: 'beans-rs.exe' From bccb40f58321a20c1a25a446d2f369d116f1cd46 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:12:28 +0000 Subject: [PATCH 10/27] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6524010..5b29e88 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ This is a complete rewrite of the original [beans](https://github.com/int-72h/of `beans-rs` is licensed under `GPLv3-only`, so please respect it! +**Note** Releases for Linux v1.4.6 and later are built with Ubuntu 20.04 (using `libssl v1.1`) + ## Developing Requirements - Rust Toolchain (nightly, only for building) From 86334de6c820bcd9a5aef85e9e0b1717d4975d21 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:13:24 +0000 Subject: [PATCH 11/27] Bump version to v1.5.0 --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4b09bf0..ec11186 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "beans-rs" -version = "1.4.5" +version = "1.5.0" edition = "2021" authors = [ "Kate Ward " diff --git a/README.md b/README.md index 5b29e88..e5c8963 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is a complete rewrite of the original [beans](https://github.com/int-72h/of `beans-rs` is licensed under `GPLv3-only`, so please respect it! -**Note** Releases for Linux v1.4.6 and later are built with Ubuntu 20.04 (using `libssl v1.1`) +**Note** Releases for Linux v1.5.0 and later are built with Ubuntu 20.04 (using `libssl v1.1`) ## Developing Requirements From 9cc6cb894eaf7691e4cdb64a12cf2dd61b498294 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:23:12 +0000 Subject: [PATCH 12/27] Update workflows to use musl --- .github/workflows/compile.yml | 13 +++++++++++-- .github/workflows/release.yml | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 8a66c5e..3a1605c 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -17,10 +17,19 @@ jobs: include: - os: ubuntu-20.04 filename: 'beans-rs' + target: x86_64-unknown-linux-musl - os: windows-latest + target: x86_64-pc-windows-msvc filename: 'beans-rs.exe' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose \ No newline at end of file + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly-2024-05-24 + target: ${{ matrix.target }} + + - uses: actions-rs/cargo@v1 + with: + command: build + args: --verbose --all-features --target ${{ matrix.target }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 133ed30..6d662ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,17 +17,24 @@ jobs: include: - os: ubuntu-20.04 filename: 'beans-rs' + target: x86_64-unknown-linux-musl + - os: windows-latest + target: x86_64-pc-windows-msvc filename: 'beans-rs.exe' + steps: - uses: actions/checkout@master - uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly-2024-05-24 + target: ${{ matrix.target }} + - uses: actions-rs/cargo@v1 with: command: build - args: --release --all-features + args: --release --all-features --target ${{ matrix.target }} + - name: Upload binaries to release uses: softprops/action-gh-release@v1 with: From 6a68f4fc77329771be4b3541896db1ec1c8af184 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:24:10 +0000 Subject: [PATCH 13/27] Update compile.yml --- .github/workflows/compile.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 3a1605c..7bd9d7d 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -32,4 +32,9 @@ jobs: - uses: actions-rs/cargo@v1 with: command: build - args: --verbose --all-features --target ${{ matrix.target }} \ No newline at end of file + args: --verbose --all-features --target ${{ matrix.target }} + - name: Archive code coverage results + uses: actions/upload-artifact@v4 + with: + name: binary-${{ matrix.os }}-${{ matrix.target }} + path: target/debug/${{ matrix.filename }} \ No newline at end of file From 54f9e0c66210b30dfdf82109639fefdbeccee5aa Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:39:21 +0000 Subject: [PATCH 14/27] Remove usage of openssl, and use rustls --- Cargo.toml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ec11186..59634e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ clap = { version = "4.5.4", features = ["cargo"] } bitflags = "2.5.0" log = "0.4.21" native-dialog = "0.7.0" -sentry = "0.34.0" lazy_static = "1.4.0" thread-id = "4.2.1" colored = "2.1.0" @@ -42,6 +41,20 @@ winconsole = { version = "0.11.1", features = ["window"] } winreg = "0.52.0" dunce = "1.0.4" +[dependencies.sentry] +version = "0.34.0" +default-features = false +features = [ + "backtrace", + "contexts", + "debug-images", + "panic", + + "reqwest", + "rustls" +] + + [dependencies.tokio] version = "1.37.0" features = [ @@ -54,8 +67,14 @@ version = "0.12.4" features = [ "multipart", "stream", - "json" + "json", + + "rustls-tls", + "charset", + "http2", + "macos-system-configuration" ] +default-features = false [target.'cfg(target_os = "windows")'.build-dependencies] winres = "0.1.12" From 8b605bf405751e21b8ecfb7c8ad2060751b658ea Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:53:09 +0000 Subject: [PATCH 15/27] Add step for installing build deps --- .github/workflows/compile.yml | 10 ++++++++++ .github/workflows/release.yml | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 7bd9d7d..654f55e 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -24,6 +24,16 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + + - name: Install Build Dependencies (ubuntu) + if: ${{ matrix.os == 'ubuntu-20.04' }} + run: | + sudo apt-get update; + sudo apt-get install -y \ + libssl-dev \ + musl-tools \ + linux-musl-dev + - uses: actions-rs/toolchain@v1 with: toolchain: nightly-2024-05-24 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d662ca..7900db8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,6 +25,16 @@ jobs: steps: - uses: actions/checkout@master + + - name: Install Build Dependencies (ubuntu) + if: ${{ matrix.os == 'ubuntu-20.04' }} + run: | + sudo apt-get update; + sudo apt-get install -y \ + libssl-dev \ + musl-tools \ + linux-musl-dev + - uses: actions-rs/toolchain@v1 with: toolchain: nightly-2024-05-24 From ece03887aaf11ed2897188d92232b1631d0afd6b Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 04:54:14 +0000 Subject: [PATCH 16/27] Update workflows --- .github/workflows/compile.yml | 3 +-- .github/workflows/release.yml | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 654f55e..3ecd329 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -31,8 +31,7 @@ jobs: sudo apt-get update; sudo apt-get install -y \ libssl-dev \ - musl-tools \ - linux-musl-dev + musl-tools - uses: actions-rs/toolchain@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7900db8..e35731c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,9 +32,8 @@ jobs: sudo apt-get update; sudo apt-get install -y \ libssl-dev \ - musl-tools \ - linux-musl-dev - + musl-tools + - uses: actions-rs/toolchain@v1 with: toolchain: nightly-2024-05-24 From 54c5c5a9c592b083dba145e0fcc9909637d7a634 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 05:03:43 +0000 Subject: [PATCH 17/27] Fix upload-artifact action for compile.yml --- .github/workflows/compile.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 3ecd329..cfc0063 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -42,8 +42,8 @@ jobs: with: command: build args: --verbose --all-features --target ${{ matrix.target }} - - name: Archive code coverage results + - name: Upload artifact uses: actions/upload-artifact@v4 with: name: binary-${{ matrix.os }}-${{ matrix.target }} - path: target/debug/${{ matrix.filename }} \ No newline at end of file + path: target/${{ matrix.target }}/debug/${{ matrix.filename }} \ No newline at end of file From 835b7a05ff4b3bc04574130a566802e5f8a668f1 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 1 Jul 2024 05:11:58 +0000 Subject: [PATCH 18/27] Update release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e35731c..c5165a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,7 @@ jobs: - name: Upload binaries to release uses: softprops/action-gh-release@v1 with: - files: target/release/${{ matrix.filename }} + files: target/${{ matrix.target }}/release/${{ matrix.filename }} tag_name: ${{ github.event.inputs.tag }} draft: false prerelease: true From fcb97b91ab8109aa91ccc312496e2bd769d99086 Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 10 Jul 2024 14:42:01 +0800 Subject: [PATCH 19/27] Add function dir_exists --- src/helper/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 6793184..8d73fd9 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -127,6 +127,14 @@ pub fn file_exists(location: String) -> bool { std::path::Path::new(&location).exists() } +/// Check if the location provided exists and it's a directory. +pub fn dir_exists(location: String) -> bool +{ + if file_exists(location.clone()) { + return is_directory(location.clone()); + } + return false; +} pub fn is_directory(location: String) -> bool { let x = PathBuf::from(&location); From 71f7d695ce7354981e686f42932fe39e5a62ab46 Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 10 Jul 2024 14:48:38 +0800 Subject: [PATCH 20/27] Add function is_steamdeck --- src/helper/mod.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 8d73fd9..c209151 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -384,6 +384,52 @@ pub fn get_tmp_dir() -> String return dir; } +/// Check if the content of `uname -r` contains `valve` (Linux Only) +/// +/// ## Returns +/// - `true` when; +/// - The output of `uname -r` contains `valve` +/// - `false` when; +/// - `target_os` is not `linux` +/// - Failed to run `uname -r` +/// - Failed to parse the stdout of `uname -r` as a String. +/// +/// ## Note +/// Will always return `false` when `cfg!(not(target_os = "linux"))`. +/// +/// This function will write to `log::trace` with the full error details before writing it to `log::warn` or `log::error`. Since errors from this +/// aren't significant, `sentry::capture_error` will not be called. +pub fn is_steamdeck() -> bool { + if cfg!(not(target_os = "linux")) { + return false; + } + + match std::process::Command::new("uname").arg("-r").output() { + Ok(cmd) => { + trace!("[helper::is_steamdeck] exit status: {}", &cmd.status); + let stdout = &cmd.stdout.to_vec(); + let stderr = &cmd.stderr.to_vec(); + if let Ok(x) = String::from_utf8(stderr.clone()) { + trace!("[helper::is_steamdeck] stderr: {}", x); + } + match String::from_utf8(stdout.clone()) { + Ok(x) => { + trace!("[helper::is_steamdeck] stdout: {}", x); + x.contains("valve") + }, + Err(e) => { + trace!("[helper::is_steamdeck] Failed to parse as utf8 {:#?}", e); + false + } + } + }, + Err(e) => { + trace!("[helper::is_steamdeck] {:#?}", e); + warn!("[helper::is_steamdeck] Failed to detect {:}", e); + return false; + } + } +} /// Generate a full file location for a temporary file. pub fn get_tmp_file(filename: String) -> String { From a6155b21e9c194095daa45a7eaad293f6384e66a Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 10 Jul 2024 14:48:53 +0800 Subject: [PATCH 21/27] Use dir_exists instead of file_exists in get_tmp_dir --- src/helper/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index c209151..38aded8 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -373,8 +373,9 @@ pub fn get_tmp_dir() -> String dir = join_path(dir, String::from("beans-rs")); dir = format_directory_path(dir); - if !file_exists(dir.clone()) { + if !dir_exists(dir.clone()) { if let Err(e) = std::fs::create_dir(&dir) { + trace!("[helper::get_tmp_dir] {:#?}", e); warn!("[helper::get_tmp_dir] failed to make tmp directory at {} ({:})", dir, e); sentry::capture_error(&e); } else { From a126ca5d9f83c89fe9e26b991e3a09eeda978fba Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 10 Jul 2024 14:49:16 +0800 Subject: [PATCH 22/27] Use ~/.tmp/ as temporary folder when on steamos/steamdeck. --- src/helper/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 38aded8..5622a14 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -364,7 +364,25 @@ pub fn format_size(i: usize) -> String { pub fn get_tmp_dir() -> String { let mut dir = std::env::temp_dir().to_str().unwrap_or("").to_string(); - if cfg!(target_os = "android") { + if is_steamdeck() { + trace!("[helper::get_tmp_dir] Detected that we are running on a steam deck. Using ~/.tmp/beans-rs"); + match simple_home_dir::home_dir() { + Some(v) => { + match v.to_str() { + Some(k) => { + dir = format_directory_path(k.to_string()); + dir = join_path(dir, String::from(".tmp")); + }, + None => { + trace!("[helper::get_tmp_dir] Failed to convert PathBuf to &str"); + } + } + }, + None => { + trace!("[helper::get_tmp_dir] Failed to get home directory."); + } + }; + } else if cfg!(target_os = "android") { dir = String::from("/data/var/tmp"); } else if cfg!(not(target_os = "windows")) { dir = String::from("/var/tmp"); From 33cf0af4ea5b3aff98fb896a69e06569721a1194 Mon Sep 17 00:00:00 2001 From: kate Date: Wed, 10 Jul 2024 18:54:59 +0800 Subject: [PATCH 23/27] Add function remove_path_head --- src/helper/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 5622a14..7c1a404 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -1,4 +1,4 @@ -#[cfg(not(target_os = "windows"))] +#[cfg(not(target_os = "windows"))] mod linux; use std::backtrace::Backtrace; @@ -172,6 +172,16 @@ pub fn join_path(tail: String, head: String) -> String format!("{}{}", format_directory_path(tail), h) } +pub fn remove_path_head(location: String) -> String +{ + let p = std::path::Path::new(&location); + if let Some(x) = p.parent() { + if let Some(m) = x.to_str() { + return m.to_string(); + } + } + return String::new(); +} /// Make sure that the location provided is formatted as a directory (ends with `crate::PATH_SEP`). pub fn format_directory_path(location: String) -> String { From 642a51fe014f6338f75629704b93e9202e6e22e2 Mon Sep 17 00:00:00 2001 From: kate Date: Wed, 10 Jul 2024 18:55:16 +0800 Subject: [PATCH 24/27] Fix get_free_space not working for some mount points --- src/helper/mod.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 7c1a404..3249a84 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -1,4 +1,4 @@ -#[cfg(not(target_os = "windows"))] +#[cfg(not(target_os = "windows"))] mod linux; use std::backtrace::Backtrace; @@ -20,6 +20,7 @@ use crate::{BeansError, DownloadFailureReason, GameinfoBackupCreateDirectoryFail use rand::{distributions::Alphanumeric, Rng}; use reqwest::header::USER_AGENT; use crate::appvar::AppVarData; +use std::collections::HashMap; #[derive(Clone, Debug)] pub enum InstallType @@ -244,17 +245,25 @@ pub fn parse_location(location: String) -> String /// Get the amount of free space on the drive in the location provided. pub fn get_free_space(location: String) -> Result { - let real_location = parse_location(location); + let mut data: HashMap = HashMap::new(); for disk in sysinfo::Disks::new_with_refreshed_list().list() { if let Some(mp) = disk.mount_point().to_str() { - if real_location.clone().starts_with(&mp) { - return Ok(disk.available_space()) - } + debug!("[get_free_space] space: {} {}", mp, disk.available_space()); + data.insert(mp.to_string(), disk.available_space()); + } + } + + let mut l = parse_location(location.clone()); + while l.len() >= 2 { + debug!("[get_free_space] Checking if {} is in data", l); + if let Some(x) = data.get(&l) { + return Ok(x.clone()); } + l = remove_path_head(l.clone()); } Err(BeansError::FreeSpaceCheckFailure { - location: real_location + location: parse_location(location.clone()) }) } /// Check if the location provided has enough free space. From bf15a4b01868b2c8ff0f52a8f5a476848a1676a5 Mon Sep 17 00:00:00 2001 From: kate Date: Wed, 10 Jul 2024 20:46:28 +0800 Subject: [PATCH 25/27] Bump version to v1.5.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 59634e2..f25b284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "beans-rs" -version = "1.5.0" +version = "1.5.1" edition = "2021" authors = [ "Kate Ward " From ae3e07fa2c8866b47674d00fd6010e04ff30c5b2 Mon Sep 17 00:00:00 2001 From: kate Date: Wed, 10 Jul 2024 20:56:22 +0800 Subject: [PATCH 26/27] Update mod.rs --- src/helper/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 3249a84..54199c1 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -131,10 +131,7 @@ pub fn file_exists(location: String) -> bool /// Check if the location provided exists and it's a directory. pub fn dir_exists(location: String) -> bool { - if file_exists(location.clone()) { - return is_directory(location.clone()); - } - return false; + file_exists(location.clone()) && is_directory(location.clone()) } pub fn is_directory(location: String) -> bool { @@ -407,6 +404,13 @@ pub fn get_tmp_dir() -> String dir = String::from("/var/tmp"); } dir = format_directory_path(dir); + if !dir_exists(dir.clone()) { + if let Err(e) = std::fs::create_dir(&dir) { + trace!("[helper::get_tmp_dir] {:#?}", e); + warn!("[helper::get_tmp_dir] failed to make tmp directory at {} ({:})", dir, e); + return; + } + } dir = join_path(dir, String::from("beans-rs")); dir = format_directory_path(dir); From faecdcb87bb8f7c0eab3fd1249f8cc21b77f68ee Mon Sep 17 00:00:00 2001 From: kate Date: Wed, 10 Jul 2024 21:00:25 +0800 Subject: [PATCH 27/27] Update mod.rs --- src/helper/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 54199c1..421b659 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -408,7 +408,6 @@ pub fn get_tmp_dir() -> String if let Err(e) = std::fs::create_dir(&dir) { trace!("[helper::get_tmp_dir] {:#?}", e); warn!("[helper::get_tmp_dir] failed to make tmp directory at {} ({:})", dir, e); - return; } } dir = join_path(dir, String::from("beans-rs"));