From bc2a4d908a2b9eca6ff16c5878f884ea2755f47a Mon Sep 17 00:00:00 2001 From: Wildan Mubarok Date: Sat, 5 Jul 2025 15:45:05 +0000 Subject: [PATCH] Add an option to not update recipes --- fetch.sh | 18 +++++++++++++++--- repo.sh | 3 +++ src/bin/cook.rs | 26 ++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/fetch.sh b/fetch.sh index 75552785..3186cb0c 100755 --- a/fetch.sh +++ b/fetch.sh @@ -3,11 +3,23 @@ set -e source config.sh -if [ $# = 0 ] +recipes="" +for arg in "${@:1}" +do + if [ "$arg" == "--nonstop" ] + then + set +e + elif [ "$arg" == "--offline" ] + then + export COOKBOOK_OFFLINE="1" + else + recipes+=" $arg" + fi +done + +if [ "$recipes" == "" ] then recipes="$(target/release/list_recipes)" -else - recipes="$@" fi for recipe_path in $recipes diff --git a/repo.sh b/repo.sh index a478cce0..9cde102b 100755 --- a/repo.sh +++ b/repo.sh @@ -17,6 +17,9 @@ do elif [ "$arg" == "--nonstop" ] then set +e + elif [ "$arg" == "--offline" ] + then + export COOKBOOK_OFFLINE="1" else recipes+=" $arg" fi diff --git a/src/bin/cook.rs b/src/bin/cook.rs index c8fc1ddd..658e0a8a 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -213,6 +213,25 @@ function DYNAMIC_INIT { } "#; +fn fetch_offline(recipe_dir: &Path, source: &Option) -> Result { + let source_dir = recipe_dir.join("source"); + match source { + Some(SourceRecipe::SameAs { same_as: _ }) | Some(SourceRecipe::Path { path: _ }) | None => { + return fetch(recipe_dir, source); + } + Some(SourceRecipe::Git { git: _, upstream: _, branch: _, rev: _, patches: _, script: _ }) | Some(SourceRecipe::Tar { tar: _, blake3: _, patches: _, script: _ }) => { + if !source_dir.is_dir() { + return Err(format!( + "'{dir}' is not exist and unable to continue in offline mode", + dir = source_dir.display(), + )); + } + } + } + + Ok(source_dir) +} + fn fetch(recipe_dir: &Path, source: &Option) -> Result { let source_dir = recipe_dir.join("source"); match source { @@ -1103,8 +1122,11 @@ fn cook( recipe: &Recipe, fetch_only: bool, ) -> Result<(), String> { - let source_dir = - fetch(recipe_dir, &recipe.source).map_err(|err| format!("failed to fetch: {}", err))?; + let is_offline = env::var("COOKBOOK_OFFLINE").unwrap_or("".to_string()) == "1"; + let source_dir = match is_offline { + true => fetch_offline(recipe_dir, &recipe.source), + false => fetch(recipe_dir, &recipe.source), + }.map_err(|err| format!("failed to fetch: {}", err))?; if fetch_only { return Ok(());