Add an option to not update recipes

This commit is contained in:
Wildan Mubarok 2025-07-05 15:45:05 +00:00
parent 3d9f377e3b
commit bc2a4d908a
3 changed files with 42 additions and 5 deletions

View File

@ -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

View File

@ -17,6 +17,9 @@ do
elif [ "$arg" == "--nonstop" ]
then
set +e
elif [ "$arg" == "--offline" ]
then
export COOKBOOK_OFFLINE="1"
else
recipes+=" $arg"
fi

View File

@ -213,6 +213,25 @@ function DYNAMIC_INIT {
}
"#;
fn fetch_offline(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, String> {
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<SourceRecipe>) -> Result<PathBuf, String> {
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(());