Skip to content

Commit f496bf5

Browse files
committedMar 8, 2025··
feat(install): add partial support for excluding files on install
1 parent 41e8105 commit f496bf5

File tree

8 files changed

+59
-15
lines changed

8 files changed

+59
-15
lines changed
 

‎soar-cli/src/cli.rs

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ pub enum Commands {
8484
/// Don't display notes
8585
#[arg(required = false, long)]
8686
no_notes: bool,
87+
88+
/// Exclude log, build/spec files, and desktop integration files
89+
///
90+
/// Note: This won't prevent desktop integration
91+
#[arg(required = false, long)]
92+
binary_only: bool,
8793
},
8894

8995
/// Search package

‎soar-cli/src/install.rs

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct InstallContext {
5454
pub retrying: Arc<AtomicU64>,
5555
pub failed: Arc<AtomicU64>,
5656
pub installed_indices: Arc<Mutex<HashSet<usize>>>,
57+
pub binary_only: bool,
5758
}
5859

5960
pub fn create_install_context(
@@ -62,6 +63,7 @@ pub fn create_install_context(
6263
portable: Option<String>,
6364
portable_home: Option<String>,
6465
portable_config: Option<String>,
66+
binary_only: bool,
6567
) -> InstallContext {
6668
let multi_progress = Arc::new(MultiProgress::new());
6769
let total_progress_bar = multi_progress.add(ProgressBar::new(total_packages as u64));
@@ -82,6 +84,7 @@ pub fn create_install_context(
8284
retrying: Arc::new(AtomicU64::new(0)),
8385
failed: Arc::new(AtomicU64::new(0)),
8486
installed_indices: Arc::new(Mutex::new(HashSet::new())),
87+
binary_only,
8588
}
8689
}
8790

@@ -93,6 +96,7 @@ pub async fn install_packages(
9396
portable_home: Option<String>,
9497
portable_config: Option<String>,
9598
no_notes: bool,
99+
binary_only: bool,
96100
) -> SoarResult<()> {
97101
let state = AppState::new();
98102
let repo_db = state.repo_db().await?;
@@ -106,6 +110,7 @@ pub async fn install_packages(
106110
portable,
107111
portable_home,
108112
portable_config,
113+
binary_only,
109114
);
110115

111116
perform_installation(install_context, install_targets, core_db.clone(), no_notes).await
@@ -440,6 +445,7 @@ pub async fn install_single_package(
440445
Some(progress_callback),
441446
core_db,
442447
target.with_pkg_id,
448+
ctx.binary_only,
443449
)
444450
.await?;
445451

‎soar-cli/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ async fn handle_cli() -> SoarResult<()> {
9595
portable_home,
9696
portable_config,
9797
no_notes,
98+
binary_only,
9899
} => {
99100
if portable.is_some() && (portable_home.is_some() || portable_config.is_some()) {
100101
error!("--portable cannot be used with --portable-home or --portable-config");
@@ -113,6 +114,7 @@ async fn handle_cli() -> SoarResult<()> {
113114
portable_home,
114115
portable_config,
115116
no_notes,
117+
binary_only,
116118
)
117119
.await?;
118120
}

‎soar-cli/src/update.rs

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub async fn update_packages(packages: Option<Vec<String>>, keep: bool) -> SoarR
143143
None,
144144
None,
145145
None,
146+
false,
146147
);
147148

148149
perform_update(ctx, update_targets, core_db.clone(), keep).await?;

‎soar-core/src/config.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use tracing::info;
1010

1111
use crate::{
1212
error::{ConfigError, SoarError},
13-
utils::{build_path, get_platform, home_config_path, home_data_path, parse_duration},
13+
utils::{
14+
build_path, default_install_excludes, get_platform, home_config_path, home_data_path,
15+
parse_duration,
16+
},
1417
};
1518

1619
type Result<T> = std::result::Result<T, ConfigError>;
@@ -143,6 +146,10 @@ pub struct Config {
143146
/// Whether to allow cross-repo updates
144147
#[serde(skip_serializing)]
145148
pub cross_repo_updates: Option<bool>,
149+
150+
/// Install excludes
151+
#[serde(skip_serializing)]
152+
pub install_excludes: Option<Vec<String>>,
146153
}
147154

148155
pub fn init() {
@@ -208,6 +215,10 @@ impl Config {
208215
config.parallel_limit = config.parallel_limit.or(Some(4));
209216
}
210217

218+
if config.install_excludes.is_none() {
219+
config.install_excludes = Some(default_install_excludes());
220+
}
221+
211222
let mut seen = HashSet::new();
212223
for repo in &mut config.repositories {
213224
if repo.name == "local" {
@@ -366,6 +377,7 @@ impl Default for Config {
366377
search_limit: Some(20),
367378
ghcr_concurrency: Some(8),
368379
cross_repo_updates: Some(false),
380+
install_excludes: Some(default_install_excludes()),
369381
}
370382
}
371383
}

‎soar-core/src/package/formats/common.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
use image::{imageops::FilterType, DynamicImage, GenericImageView};
1010
use regex::Regex;
1111
use soar_dl::downloader::{DownloadOptions, Downloader};
12-
use tracing::info;
1312

1413
use crate::{
1514
config::get_config,
@@ -68,7 +67,6 @@ pub fn symlink_icon<P: AsRef<Path>>(real_path: P) -> SoarResult<PathBuf> {
6867
let ext = real_path.extension();
6968

7069
let (w, h) = if ext == Some(OsStr::new("svg")) {
71-
info!("CAME HERE??");
7270
(128, 128)
7371
} else {
7472
let image = image::open(real_path)?;

‎soar-core/src/package/install.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::{
2-
env,
3-
ffi::OsString,
4-
fs,
2+
env, fs,
53
path::{Path, PathBuf},
64
sync::{Arc, Mutex},
75
thread::sleep,
@@ -22,7 +20,7 @@ use crate::{
2220
packages::{FilterCondition, PackageQueryBuilder, ProvideStrategy},
2321
},
2422
error::{ErrorContext, SoarError},
25-
utils::{desktop_dir, icons_dir, process_dir},
23+
utils::{default_install_excludes, desktop_dir, icons_dir, process_dir},
2624
SoarResult,
2725
};
2826

@@ -32,6 +30,7 @@ pub struct PackageInstaller {
3230
progress_callback: Option<Arc<dyn Fn(DownloadState) + Send + Sync>>,
3331
db: Arc<Mutex<Connection>>,
3432
with_pkg_id: bool,
33+
binary_only: bool,
3534
}
3635

3736
#[derive(Clone)]
@@ -49,6 +48,7 @@ impl PackageInstaller {
4948
progress_callback: Option<Arc<dyn Fn(DownloadState) + Send + Sync>>,
5049
db: Arc<Mutex<Connection>>,
5150
with_pkg_id: bool,
51+
binary_only: bool,
5252
) -> SoarResult<Self> {
5353
let install_dir = install_dir.as_ref().to_path_buf();
5454
let package = &target.package;
@@ -90,6 +90,7 @@ impl PackageInstaller {
9090
progress_callback,
9191
db: db.clone(),
9292
with_pkg_id,
93+
binary_only,
9394
})
9495
}
9596

@@ -114,14 +115,27 @@ impl PackageInstaller {
114115

115116
if self.package.ghcr_pkg.is_some() {
116117
let progress_callback = &self.progress_callback.clone();
118+
let exclude_keywords = self
119+
.binary_only
120+
.then_some(
121+
default_install_excludes()
122+
.into_iter()
123+
.chain(
124+
[".png", ".svg", "LICENSE", ".version", "CHECKSUM"]
125+
.iter()
126+
.map(|s| s.to_string()),
127+
)
128+
.collect::<Vec<String>>(),
129+
)
130+
.unwrap_or_else(|| get_config().install_excludes.clone().unwrap_or_default());
117131
let options = OciDownloadOptions {
118132
url: url.to_string(),
119133
output_path: Some(output_path.to_string_lossy().to_string()),
120134
progress_callback: self.progress_callback.clone(),
121135
api: None,
122136
concurrency: Some(get_config().ghcr_concurrency.unwrap_or(8)),
123137
regex_patterns: Vec::new(),
124-
exclude_keywords: Vec::new(),
138+
exclude_keywords,
125139
match_keywords: Vec::new(),
126140
exact_case: false,
127141
};
@@ -335,13 +349,11 @@ impl PackageInstaller {
335349
let installed_path = PathBuf::from(&package.installed_path);
336350

337351
let mut remove_action = |path: &Path| -> SoarResult<()> {
338-
if path.extension() == Some(&OsString::from("desktop")) {
339-
if let Ok(real_path) = fs::read_link(&path) {
340-
if real_path.parent() == Some(&installed_path) {
341-
fs::remove_file(&path).with_context(|| {
342-
format!("removing desktop file {}", path.display())
343-
})?;
344-
}
352+
if let Ok(real_path) = fs::read_link(&path) {
353+
if real_path.parent() == Some(&installed_path) {
354+
fs::remove_file(&path).with_context(|| {
355+
format!("removing desktop file {}", path.display())
356+
})?;
345357
}
346358
}
347359
Ok(())

‎soar-core/src/utils.rs

+7
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,10 @@ pub fn parse_duration(input: &str) -> Option<u128> {
302302

303303
Some(multiplier * number)
304304
}
305+
306+
pub fn default_install_excludes() -> Vec<String> {
307+
[".log", "SBUILD", ".json"]
308+
.into_iter()
309+
.map(String::from)
310+
.collect::<Vec<String>>()
311+
}

0 commit comments

Comments
 (0)
Please sign in to comment.