Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "avocado-cli"
version = "0.21.0"
version = "0.22.0"
edition = "2021"
description = "Command line interface for Avocado."
authors = ["Avocado"]
Expand Down
72 changes: 70 additions & 2 deletions src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};

use crate::utils::config::Config;
use crate::utils::container::{RunConfig, SdkContainer};
use crate::utils::lockfile::LockFile;
use crate::utils::output::{print_error, print_info, print_success, OutputLevel};
use crate::utils::target::resolve_target_required;
use crate::utils::volume::{VolumeManager, VolumeState};
Expand All @@ -22,12 +23,14 @@ pub struct CleanCommand {
verbose: bool,
/// Whether to remove stamp files
stamps: bool,
/// Path to configuration file (needed for --stamps)
/// Path to configuration file (needed for --stamps and --unlock)
config_path: Option<String>,
/// Target architecture (needed for --stamps)
/// Target architecture (needed for --stamps and --unlock)
target: Option<String>,
/// Force removal by killing and removing containers using the volume
force: bool,
/// Whether to unlock (clear lock file entries) for all sysroots
unlock: bool,
}

impl CleanCommand {
Expand All @@ -53,6 +56,7 @@ impl CleanCommand {
config_path: None,
target: None,
force: false,
unlock: false,
}
}

Expand Down Expand Up @@ -80,6 +84,12 @@ impl CleanCommand {
self
}

/// Set whether to unlock (clear lock file entries) for all sysroots
pub fn with_unlock(mut self, unlock: bool) -> Self {
self.unlock = unlock;
self
}

/// Executes the clean command, removing volumes, state files, and optionally legacy directories.
///
/// # Returns
Expand Down Expand Up @@ -125,6 +135,64 @@ impl CleanCommand {
self.clean_stamps(&directory_path).await?;
}

// Unlock (clear lock file entries) if requested
if self.unlock {
self.unlock_all(&directory_path)?;
}

Ok(())
}

/// Unlock (clear lock file entries) for all sysroots
fn unlock_all(&self, _directory_path: &Path) -> Result<()> {
let config_path = self.config_path.as_ref().ok_or_else(|| {
anyhow::anyhow!("--unlock requires a config file to be specified with -C/--config")
})?;

let config = Config::load(config_path)?;
let target = resolve_target_required(self.target.as_deref(), &config)?;

// Get src_dir from config
let src_dir = config.get_resolved_src_dir(config_path).unwrap_or_else(|| {
Path::new(config_path)
.parent()
.unwrap_or(Path::new("."))
.to_path_buf()
});

// Load lock file
let mut lock_file = LockFile::load(&src_dir)
.with_context(|| format!("Failed to load lock file from {}", src_dir.display()))?;

if lock_file.is_empty() {
if self.verbose {
print_info(
"Lock file is empty, nothing to unlock.",
OutputLevel::Normal,
);
}
return Ok(());
}

// Clear all entries for the target
if self.verbose {
print_info(
&format!("Unlocking all entries for target '{}'", target),
OutputLevel::Normal,
);
}
lock_file.clear_all(&target);

// Save updated lock file
lock_file
.save(&src_dir)
.with_context(|| "Failed to save lock file")?;

print_success(
&format!("Unlocked all entries for target '{}'.", target),
OutputLevel::Normal,
);

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/ext/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ $DNF_SDK_HOST \
repo_url.cloned(),
repo_release.cloned(),
merged_container_args.clone(),
runs_on_context,
)
.await?;

Expand Down
13 changes: 10 additions & 3 deletions src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::utils::{
container::SdkContainer,
lockfile::{build_package_spec_with_lock, LockFile, SysrootType},
output::{print_info, print_success, OutputLevel},
stamps::get_local_arch,
target::validate_and_log_target,
};

Expand Down Expand Up @@ -807,6 +808,7 @@ $DNF_SDK_HOST \
repo_url,
repo_release,
merged_container_args,
None, // TODO: Add runs_on_context support to install.rs
)
.await?;

Expand Down Expand Up @@ -1050,6 +1052,7 @@ $DNF_SDK_HOST \
repo_url,
repo_release,
merged_container_args,
None, // TODO: Add runs_on_context support to install.rs
)
.await?;

Expand Down Expand Up @@ -1145,6 +1148,9 @@ $DNF_SDK_HOST \
};

// Build list of SDK packages to install (using lock file for version pinning)
// SDK packages are keyed by host architecture since they run on the host
let sdk_sysroot = SysrootType::Sdk(get_local_arch().to_string());

let mut sdk_packages = Vec::new();
let mut sdk_package_names = Vec::new();
for (pkg_name_val, version_spec) in sdk_deps_map {
Expand All @@ -1166,7 +1172,7 @@ $DNF_SDK_HOST \
let package_spec = build_package_spec_with_lock(
lock_file,
target,
&SysrootType::Sdk,
&sdk_sysroot,
pkg_name,
&config_version,
);
Expand Down Expand Up @@ -1261,18 +1267,19 @@ $DNF_SDK_HOST \
if !sdk_package_names.is_empty() {
let installed_versions = container_helper
.query_installed_packages(
&SysrootType::Sdk,
&sdk_sysroot,
&sdk_package_names,
container_image,
target,
repo_url,
repo_release,
merged_container_args,
None, // TODO: Add runs_on_context support to install.rs
)
.await?;

if !installed_versions.is_empty() {
lock_file.update_sysroot_versions(target, &SysrootType::Sdk, installed_versions);
lock_file.update_sysroot_versions(target, &sdk_sysroot, installed_versions);
if self.verbose {
print_info(
&format!("Updated lock file with SDK dependencies from external config '{external_config_path}'."),
Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub mod runtime;
pub mod sdk;
pub mod sign;
pub mod signing_keys;
pub mod unlock;
pub mod upgrade;
1 change: 1 addition & 0 deletions src/commands/runtime/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ $DNF_SDK_HOST \
repo_url.cloned(),
repo_release.cloned(),
merged_container_args.clone(),
runs_on_context,
)
.await?;

Expand Down
Loading