Skip to content

Commit

Permalink
Merge pull request #21 from eXhumer/main
Browse files Browse the repository at this point in the history
feat: add support for custom compression options
  • Loading branch information
SkyLeite authored Oct 13, 2024
2 parents 7237ba7 + 38c7d15 commit ff389ae
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 106 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
93 changes: 45 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "decky"
version = "0.0.3"
version = "0.0.5"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,7 +9,7 @@ edition = "2021"
anyhow = "1.0.68"
boolinator = "2.4.0"
clap = { version = "4.1.4", features = ["derive"] }
flexi_logger = "0.24"
flexi_logger = "0.29"
futures = "0.3.25"
glob = "0.3.1"
itertools = "0.10.5"
Expand All @@ -20,8 +20,8 @@ serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
sha2 = "0.10.7"
tokio = { version = "1.24.2", features = ["full"] }
users = "0.11.0"
uzers = "0.12.1"
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"
18 changes: 18 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ impl ContainerEngine {
}


#[derive(clap::ValueEnum, Clone)]
pub enum CompressMethod {
Deflate,
Store,
}

#[derive(Subcommand)]
pub enum Command {
Plugin(PluginCLI),
Expand Down Expand Up @@ -70,6 +76,12 @@ pub enum PluginCommand {

#[arg(short = 'e', long = "engine", default_value = "docker")]
container_engine: ContainerEngine,

#[arg(short = 'm', long, default_value = "deflate")]
compression_method: CompressMethod,

#[arg(short = 'l', long)]
compression_level: Option<i32>,
},
New,
Deploy {
Expand All @@ -94,6 +106,12 @@ pub enum PluginCommand {
#[arg(short = 'e', long = "engine", default_value = "docker")]
container_engine: ContainerEngine,

#[arg(short = 'm', long, default_value = "deflate")]
compression_method: CompressMethod,

#[arg(short = 'l', long)]
compression_level: Option<i32>,

#[arg(short = 'S', long, default_value = "true")]
follow_symlinks: bool,

Expand Down
30 changes: 25 additions & 5 deletions src/cli/plugin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand All @@ -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<i32>,
}

impl Builder {
Expand Down Expand Up @@ -216,7 +218,7 @@ impl Builder {
filename: &str,
path: PathBuf,
zip: &mut ZipWriter<File>,
perms: FileOptions,
opts: FileOptions,
) -> Result<()> {
let name = path
.strip_prefix(&self.tmp_build_root)
Expand All @@ -233,11 +235,25 @@ 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 {
opts = match self.compression_level {
Some(level) => opts.compression_level(Some(level)),
None => opts.compression_level(Some(9))
}
}

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(())
Expand Down Expand Up @@ -395,6 +411,8 @@ impl Builder {
follow_symlinks: bool,
output_filename_source: FilenameSource,
container_engine: ContainerEngine,
compression_method: CompressMethod,
compression_level: Option<i32>,
) -> Result<Self> {
if !output_root.exists() {
std::fs::create_dir(&output_root)?;
Expand All @@ -421,6 +439,8 @@ impl Builder {
follow_symlinks,
output_filename_source,
container_engine,
compression_method,
compression_level,
})
}
}
Loading

0 comments on commit ff389ae

Please sign in to comment.