feat: new step Lensfun's database update (#839)
* feat: new step Lensfun's database update * refactor: take 1 as a success exit code
This commit is contained in:
@@ -244,3 +244,10 @@
|
|||||||
[containers]
|
[containers]
|
||||||
# Specify the containers to ignore while updating (Wildcard supported)
|
# Specify the containers to ignore while updating (Wildcard supported)
|
||||||
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest", "docker.io*"]
|
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest", "docker.io*"]
|
||||||
|
|
||||||
|
[lensfun]
|
||||||
|
# If disabled, Topgrade invokes `lensfun‑update‑data` without root priviledge,
|
||||||
|
# then the update will be only available to you. Otherwise, `sudo` is required,
|
||||||
|
# and the update will be installed system-wide, i.e., available to all users.
|
||||||
|
# (default: false)
|
||||||
|
# use_sudo = false
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ pub enum Step {
|
|||||||
Helix,
|
Helix,
|
||||||
Krew,
|
Krew,
|
||||||
Lure,
|
Lure,
|
||||||
|
Lensfun,
|
||||||
Macports,
|
Macports,
|
||||||
Mamba,
|
Mamba,
|
||||||
Miktex,
|
Miktex,
|
||||||
@@ -396,6 +397,12 @@ pub struct Misc {
|
|||||||
log_filters: Option<Vec<String>>,
|
log_filters: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default, Debug, Merge)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct Lensfun {
|
||||||
|
use_sudo: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, Debug, Merge)]
|
#[derive(Deserialize, Default, Debug, Merge)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
/// Configuration file
|
/// Configuration file
|
||||||
@@ -456,6 +463,9 @@ pub struct ConfigFile {
|
|||||||
|
|
||||||
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
||||||
distrobox: Option<Distrobox>,
|
distrobox: Option<Distrobox>,
|
||||||
|
|
||||||
|
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
||||||
|
lensfun: Option<Lensfun>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config_directory() -> PathBuf {
|
fn config_directory() -> PathBuf {
|
||||||
@@ -1523,6 +1533,14 @@ impl Config {
|
|||||||
|
|
||||||
self.opt.custom_commands.iter().any(|s| s == name)
|
self.opt.custom_commands.iter().any(|s| s == name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lensfun_use_sudo(&self) -> bool {
|
||||||
|
self.config_file
|
||||||
|
.lensfun
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|lensfun| lensfun.use_sudo)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -412,6 +412,9 @@ fn run() -> Result<()> {
|
|||||||
runner.execute(Step::PlatformioCore, "PlatformIO Core", || {
|
runner.execute(Step::PlatformioCore, "PlatformIO Core", || {
|
||||||
generic::run_platform_io(&ctx)
|
generic::run_platform_io(&ctx)
|
||||||
})?;
|
})?;
|
||||||
|
runner.execute(Step::Lensfun, "Lensfun's database update", || {
|
||||||
|
generic::run_lensfun_update_data(&ctx)
|
||||||
|
})?;
|
||||||
|
|
||||||
if should_run_powershell {
|
if should_run_powershell {
|
||||||
runner.execute(Step::Powershell, "Powershell Modules Update", || {
|
runner.execute(Step::Powershell, "Powershell Modules Update", || {
|
||||||
|
|||||||
@@ -977,3 +977,28 @@ pub fn run_platform_io(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
|
|
||||||
ctx.run_type().execute(bin_path).arg("upgrade").status_checked()
|
ctx.run_type().execute(bin_path).arg("upgrade").status_checked()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run `lensfun-update-data` to update lensfun database.
|
||||||
|
///
|
||||||
|
/// `sudo` will be used if `use_sudo` configuration entry is set to true.
|
||||||
|
pub fn run_lensfun_update_data(ctx: &ExecutionContext) -> Result<()> {
|
||||||
|
const SEPARATOR: &str = "Lensfun's database update";
|
||||||
|
let lensfun_update_data = require("lensfun-update-data")?;
|
||||||
|
const EXIT_CODE_WHEN_NO_UPDATE: i32 = 1;
|
||||||
|
|
||||||
|
if ctx.config().lensfun_use_sudo() {
|
||||||
|
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
||||||
|
print_separator(SEPARATOR);
|
||||||
|
ctx.run_type()
|
||||||
|
.execute(sudo)
|
||||||
|
.arg(lensfun_update_data)
|
||||||
|
// `lensfun-update-data` returns 1 when there is no update available
|
||||||
|
// which should be considered success
|
||||||
|
.status_checked_with_codes(&[EXIT_CODE_WHEN_NO_UPDATE])
|
||||||
|
} else {
|
||||||
|
print_separator(SEPARATOR);
|
||||||
|
ctx.run_type()
|
||||||
|
.execute(lensfun_update_data)
|
||||||
|
.status_checked_with_codes(&[EXIT_CODE_WHEN_NO_UPDATE])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user