diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b3d9bff..c773711 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,7 +40,7 @@ jobs: outputs: version: ${{ steps.version.outputs.version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Rust cache for ${{ matrix.platform.release_for }} uses: Swatinem/rust-cache@v2 @@ -58,7 +58,7 @@ jobs: strip: true - name: Upload binary - uses: actions/upload-artifact@v3.1.2 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.platform.name }} path: target/${{ matrix.platform.target }}/release/decky @@ -70,7 +70,7 @@ jobs: contents: write if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Grab version id: version @@ -79,7 +79,7 @@ jobs: echo "Version code is $version" echo "version=$version" >> $GITHUB_OUTPUT - - uses: actions/download-artifact@v4.1.7 + - uses: actions/download-artifact@v4 with: path: artifacts diff --git a/Cargo.lock b/Cargo.lock index bf46d3e..172daf3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "aho-corasick" version = "1.0.4" @@ -123,7 +129,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.1", "object", "rustc-demangle", ] @@ -399,6 +405,16 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +[[package]] +name = "flate2" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.0", +] + [[package]] name = "flexi_logger" version = "0.24.2" @@ -833,6 +849,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "mio" version = "0.8.11" @@ -1846,4 +1871,5 @@ dependencies = [ "byteorder", "crc32fast", "crossbeam-utils", + "flate2", ] diff --git a/Cargo.toml b/Cargo.toml index 589ae2e..a000ad9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,6 @@ sha2 = "0.10.7" tokio = { version = "1.24.2", features = ["full"] } users = "0.11.0" walkdir = "2.3.2" -zip = { version = "0.6.3", default-features = false } +zip = { version = "0.6.3", default-features = false, features = ["deflate"] } which = "4.4.0" dirs = "5" diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 7b5f3a0..74e29a9 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -27,6 +27,12 @@ impl ContainerEngine { } +#[derive(clap::ValueEnum, Clone)] +pub enum CompressMethod { + Deflate, + Store, +} + #[derive(Subcommand)] pub enum Command { Plugin(PluginCLI), @@ -70,6 +76,12 @@ pub enum PluginCommand { #[arg(short = 'e', long = "engine", default_value = "docker")] container_engine: ContainerEngine, + + #[arg(short = 'm', long, default_value = "store")] + compression_method: CompressMethod, + + #[arg(short = 'l', long)] + compression_level: Option, }, New, Deploy { @@ -94,6 +106,12 @@ pub enum PluginCommand { #[arg(short = 'e', long = "engine", default_value = "docker")] container_engine: ContainerEngine, + #[arg(short = 'm', long, default_value = "store")] + compression_method: CompressMethod, + + #[arg(short = 'l', long)] + compression_level: Option, + #[arg(short = 'S', long, default_value = "true")] follow_symlinks: bool, diff --git a/src/cli/plugin/build.rs b/src/cli/plugin/build.rs index 313ef4a..4d3f37e 100644 --- a/src/cli/plugin/build.rs +++ b/src/cli/plugin/build.rs @@ -14,10 +14,10 @@ use std::{ path::{Path, PathBuf}, }; use walkdir::WalkDir; -use zip::{write::FileOptions, ZipWriter}; +use zip::{write::FileOptions, CompressionMethod, ZipWriter}; use crate::{ - cli::{FilenameSource, ContainerEngine}, + cli::{CompressMethod, ContainerEngine, FilenameSource}, container_engine, plugin::{CustomBackend, Plugin}, }; @@ -35,6 +35,8 @@ pub struct Builder { pub follow_symlinks: bool, pub output_filename_source: FilenameSource, pub container_engine: ContainerEngine, + pub compression_method: CompressMethod, + pub compression_level: Option, } impl Builder { @@ -216,7 +218,7 @@ impl Builder { filename: &str, path: PathBuf, zip: &mut ZipWriter, - perms: FileOptions, + opts: FileOptions, ) -> Result<()> { let name = path .strip_prefix(&self.tmp_build_root) @@ -233,11 +235,22 @@ impl Builder { if path.is_file() { let bytes = std::fs::read(&path).unwrap(); - zip.start_file(name.to_str().unwrap(), perms)?; + let method = match self.compression_method { + CompressMethod::Deflate => CompressionMethod::Deflated, + CompressMethod::Store => CompressionMethod::Stored, + }; + + let mut opts = opts.compression_method(method); + + if method == CompressionMethod::Deflated && self.compression_level.is_some() { + opts = opts.compression_level(Some(self.compression_level.unwrap())); + } + + zip.start_file(name.to_str().unwrap(), opts)?; zip.write_all(&bytes)?; } else if !name.as_os_str().is_empty() { - zip.add_directory(name.to_str().unwrap(), perms)?; + zip.add_directory(name.to_str().unwrap(), opts)?; } Ok(()) @@ -395,6 +408,8 @@ impl Builder { follow_symlinks: bool, output_filename_source: FilenameSource, container_engine: ContainerEngine, + compression_method: CompressMethod, + compression_level: Option, ) -> Result { if !output_root.exists() { std::fs::create_dir(&output_root)?; @@ -421,6 +436,8 @@ impl Builder { follow_symlinks, output_filename_source, container_engine, + compression_method, + compression_level, }) } } diff --git a/src/cli/plugin/deploy.rs b/src/cli/plugin/deploy.rs index 7da43fc..5b12154 100644 --- a/src/cli/plugin/deploy.rs +++ b/src/cli/plugin/deploy.rs @@ -7,6 +7,7 @@ use log::info; use rand::distributions::{Alphanumeric, DistString}; use crate::cli::plugin::build::Builder; +use crate::cli::CompressMethod; use crate::plugin::DeckFile; use crate::{cli::FilenameSource, cli::ContainerEngine, plugin::Plugin}; @@ -231,6 +232,8 @@ impl Deployer { follow_symlinks: bool, output_filename_source: FilenameSource, container_engine: ContainerEngine, + compression_method: CompressMethod, + compression_level: Option, deck_ip: Option, deck_port: Option, deck_pass: Option, @@ -248,6 +251,8 @@ impl Deployer { follow_symlinks, output_filename_source, container_engine, + compression_method, + compression_level, ) .expect("Could not create builder"); diff --git a/src/cli/plugin/mod.rs b/src/cli/plugin/mod.rs index 287929c..2de7ea5 100644 --- a/src/cli/plugin/mod.rs +++ b/src/cli/plugin/mod.rs @@ -14,7 +14,9 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { build_with_dev, follow_symlinks, output_filename_source, - container_engine + container_engine, + compression_method, + compression_level, } => { build::Builder::new( plugin_path.into(), @@ -25,6 +27,8 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { follow_symlinks.clone(), output_filename_source.clone(), container_engine.clone(), + compression_method.clone(), + compression_level.clone(), )? .run() .await @@ -44,6 +48,8 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { deck_pass, deck_key, deck_dir, + compression_method, + compression_level, } => { deploy::Deployer::new( plugin_path.into(), @@ -54,6 +60,8 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { follow_symlinks.clone(), output_filename_source.clone(), container_engine.clone(), + compression_method.clone(), + compression_level.clone(), deck_ip.clone(), deck_port.clone(), deck_pass.clone(),