- Core crate: Minimal shell-out implementation - Advanced crate: Pluggable backends and enhanced features - Main crate: Re-exports core + optional advanced features - Feature flags: Users choose complexity level - Examples: Working demonstrations of both approaches - Documentation: Clear README explaining the structure Implements the refined two-crate approach with workspace + feature flags.
63 lines
2.5 KiB
Rust
63 lines
2.5 KiB
Rust
//! Example demonstrating the atomicity limitations of the APT-DNF Bridge.
|
|
//!
|
|
//! This example shows how the APT-DNF Bridge provides transaction-like semantics
|
|
//! but does NOT provide true system-level atomicity.
|
|
|
|
use apt_dnf_bridge::{Package, Transaction};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("APT-DNF Bridge - Atomicity Notes Example");
|
|
println!("=====================================");
|
|
|
|
// Create a transaction
|
|
let mut tx = Transaction::new();
|
|
|
|
// Add some operations
|
|
let vim = Package::new("vim", "2:8.1.2269-1ubuntu5.14", "amd64");
|
|
let nano = Package::new("nano", "2.9.3-2", "amd64");
|
|
|
|
tx.add_install(vim).await?;
|
|
tx.add_install(nano).await?;
|
|
|
|
println!("Created transaction with {} operations", tx.len());
|
|
|
|
// Resolve dependencies (this will validate the transaction)
|
|
println!("Resolving dependencies...");
|
|
tx.resolve().await?;
|
|
println!("✓ Dependencies resolved successfully");
|
|
|
|
// IMPORTANT: The commit() method does NOT provide true atomicity
|
|
println!("\n⚠️ IMPORTANT ATOMICITY NOTES:");
|
|
println!(" • This transaction provides transaction-like semantics");
|
|
println!(" • It does NOT provide true system-level atomicity");
|
|
println!(" • If the operation fails midway, the system could be left in a corrupted state");
|
|
println!(" • For true atomicity, apt-ostree must handle this at a higher level");
|
|
println!(" • This might involve operating on a temporary directory and performing an atomic pivot_root");
|
|
|
|
println!("\nTransaction operations:");
|
|
for (i, op) in tx.operations().iter().enumerate() {
|
|
match op {
|
|
apt_dnf_bridge::Operation::Install(pkg) => {
|
|
println!(" {}: Install {}", i + 1, pkg.name);
|
|
}
|
|
apt_dnf_bridge::Operation::Remove(pkg) => {
|
|
println!(" {}: Remove {}", i + 1, pkg.name);
|
|
}
|
|
apt_dnf_bridge::Operation::Upgrade(pkg) => {
|
|
println!(" {}: Upgrade {}", i + 1, pkg.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
println!("\nTo commit this transaction (commented out for safety):");
|
|
println!(" tx.commit().await?;");
|
|
|
|
println!("\nFor apt-ostree integration, consider:");
|
|
println!(" 1. Operating on a temporary directory");
|
|
println!(" 2. Performing all APT operations there");
|
|
println!(" 3. Using atomic pivot_root to switch to the new system state");
|
|
println!(" 4. Rolling back if any step fails");
|
|
|
|
Ok(())
|
|
}
|