From 98657edb60c228e5115e82df1f947b07d1ff3778 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Wed, 3 Jun 2020 22:12:27 +0300 Subject: [PATCH] Allow tlmgr to run in Linux (fix #406) --- config.example.toml | 1 + src/config.rs | 11 +++++++++++ src/execution_context.rs | 4 +--- src/main.rs | 11 +---------- src/steps/generic.rs | 17 +++++++++++++---- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/config.example.toml b/config.example.toml index a4225412..a75ef178 100644 --- a/config.example.toml +++ b/config.example.toml @@ -58,3 +58,4 @@ # Arguments to pass yay when updating packages #yay_arguments = "--nodevel" #trizen_arguments = "--devel" +#enable_tlmgr = true diff --git a/src/config.rs b/src/config.rs index 316a825b..ad8d5a07 100644 --- a/src/config.rs +++ b/src/config.rs @@ -60,6 +60,7 @@ pub struct Linux { yay_arguments: Option, trizen_arguments: Option, dnf_arguments: Option, + enable_tlmgr: Option, } #[derive(Deserialize, Default, Debug)] @@ -439,6 +440,16 @@ impl Config { .and_then(|linux| linux.dnf_arguments.as_deref()) } + /// Extra yay arguments + #[allow(dead_code)] + pub fn enable_tlmgr_linux(&self) -> bool { + self.config_file + .linux + .as_ref() + .and_then(|linux| linux.enable_tlmgr) + .unwrap_or(false) + } + pub fn use_predefined_git_repos(&self) -> bool { !self.opt.disable_predefined_git_repos && self.config_file.predefined_git_repos.unwrap_or(true) } diff --git a/src/execution_context.rs b/src/execution_context.rs index 73e0e1d9..f1ef10fd 100644 --- a/src/execution_context.rs +++ b/src/execution_context.rs @@ -3,12 +3,10 @@ use crate::config::Config; use crate::executor::RunType; use crate::git::Git; use directories::BaseDirs; -#[cfg(unix)] use std::path::PathBuf; pub struct ExecutionContext<'a> { run_type: RunType, - #[cfg(unix)] sudo: &'a Option, git: &'a Git, config: &'a Config, @@ -37,6 +35,7 @@ impl<'a> ExecutionContext<'a> { pub fn new(run_type: RunType, git: &'a Git, config: &'a Config, base_dirs: &'a BaseDirs) -> ExecutionContext<'a> { ExecutionContext { run_type, + sudo: &None, config, git, base_dirs, @@ -51,7 +50,6 @@ impl<'a> ExecutionContext<'a> { &self.git } - #[cfg(unix)] pub fn sudo(&self) -> &Option { &self.sudo } diff --git a/src/main.rs b/src/main.rs index d94fe7b2..dff68d91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -280,16 +280,7 @@ fn run() -> Result<()> { } if config.should_run(Step::Tlmgr) { - #[cfg(not(target_os = "linux"))] - runner.execute("tlmgr", || { - generic::run_tlmgr_update( - #[cfg(unix)] - &sudo, - #[cfg(windows)] - &None, - run_type, - ) - })?; + runner.execute("tlmgr", || generic::run_tlmgr_update(&ctx))?; } if config.should_run(Step::Myrepos) { diff --git a/src/steps/generic.rs b/src/steps/generic.rs index d725a10d..9b9f2b91 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -117,8 +117,15 @@ pub fn run_stack_update(run_type: RunType) -> Result<()> { run_type.execute(&stack).arg("upgrade").check_run() } -#[cfg(not(target_os = "linux"))] -pub fn run_tlmgr_update(sudo: &Option, run_type: RunType) -> Result<()> { +pub fn run_tlmgr_update(ctx: &ExecutionContext) -> Result<()> { + cfg_if::cfg_if! { + if #[cfg(target_os = "linux")] { + if !ctx.config().enable_tlmgr_linux() { + return Err(SkipStep.into()); + } + } + } + let tlmgr = utils::require("tlmgr")?; let kpsewhich = utils::require("kpsewhich")?; let tlmgr_directory = { @@ -142,9 +149,11 @@ pub fn run_tlmgr_update(sudo: &Option, run_type: RunType) -> Result<()> print_separator("TeX Live package manager"); let mut command = if directory_writable { - run_type.execute(&tlmgr) + ctx.run_type().execute(&tlmgr) } else { - let mut c = run_type.execute(sudo.as_ref().ok_or(TopgradeError::SudoRequired)?); + let mut c = ctx + .run_type() + .execute(ctx.sudo().as_ref().ok_or(TopgradeError::SudoRequired)?); c.arg(&tlmgr); c };