pub struct Cache {
    pub ptr: Rc<RefCell<UniquePtr<PkgCacheFile>>>,
    pub records: Rc<RefCell<Records>>,
    /* private fields */
}
Expand description

The main struct for accessing any and all apt data.

Fields

ptr: Rc<RefCell<UniquePtr<PkgCacheFile>>>records: Rc<RefCell<Records>>

Implementations

Initialize the configuration system, open and return the cache.

This is the entry point for all operations of this crate.

Clear the entire cache and start new.

This function would be used after cache.update Or after do_install if you plan on making more changes

Updates the package cache and returns a Result

Here is an example of how you may parse the Error messages.

use rust_apt::cache::Cache;
use rust_apt::progress::{AcquireProgress, AptAcquireProgress};

let cache = Cache::new();
let mut progress: Box<dyn AcquireProgress> = Box::new(AptAcquireProgress::new());
if let Err(error) = cache.update(&mut progress) {
    for msg in error.what().split(';') {
        if msg.starts_with("E:") {
        println!("Error: {}", &msg[2..]);
        }
        if msg.starts_with("W:") {
            println!("Warning: {}", &msg[2..]);
        }
    }
}
Known Errors:
  • E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
  • E:Unable to lock directory /var/lib/apt/lists/

Mark all packages for upgrade

Example:
use rust_apt::cache::{Cache, Upgrade};

let cache = Cache::new();

cache.upgrade(&Upgrade::FullUpgrade).unwrap();

An iterator over the packages that will be altered when cache.commit() is called.

sort_name:
  • true = Packages will be in alphabetical order
  • false = Packages will not be sorted by name

Resolve dependencies with the changes marked on all packages. This marks additional packages for installation/removal to satisfy the dependency chain.

Note that just running a mark_* function on a package doesn’t guarantee that the selected state will be kept during dependency resolution. If you need such, make sure to run crate::package::Package::protect after marking your requested modifications.

If fix_broken is set to true, the library will try to repair broken dependencies of installed packages.

Returns Err if there was an error reaching dependency resolution.

Fetch any archives needed to complete the transaction.

Returns:
  • A Result enum: the Ok variant if fetching succeeded, and Err if there was an issue.
Example:
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
use rust_apt::progress::{AptAcquireProgress};

let cache = Cache::new();
let pkg = cache.get("neovim").unwrap();
let mut progress = AptAcquireProgress::new_box();

pkg.set(&Mark::Install).then_some(()).unwrap();
pkg.protect();
cache.resolve(true).unwrap();

cache.get_archives(&mut progress).unwrap();
Known Errors:
  • W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
  • W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
  • W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
  • W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
  • W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
  • W:Problem unlinking the file /var/log/apt/eipp.log.xz - FileFd::Open (13: Permission denied)
  • W:Could not open file /var/log/apt/eipp.log.xz - open (17: File exists)
  • W:Could not open file ‘/var/log/apt/eipp.log.xz’ - EIPP::OrderInstall (17: File exists)
  • E:Internal Error, ordering was unable to handle the media swap“

Install, remove, and do any other actions requested by the cache.

Returns:
  • A Result enum: the Ok variant if transaction was successful, and Err if there was an issue.
Example:
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
use rust_apt::progress::{AptAcquireProgress, AptInstallProgress};

let cache = Cache::new();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AptAcquireProgress::new_box();
let mut install_progress = AptInstallProgress::new_box();

pkg.set(&Mark::Install).then_some(()).unwrap();
pkg.protect();
cache.resolve(true).unwrap();

// These need root
// cache.get_archives(&mut acquire_progress).unwrap();
// cache.do_install(&mut install_progress).unwrap();
Known Errors:
  • W:Problem unlinking the file /var/log/apt/eipp.log.xz - FileFd::Open (13: Permission denied)
  • W:Could not open file /var/log/apt/eipp.log.xz - open (17: File exists)
  • W:Could not open file ‘/var/log/apt/eipp.log.xz’ - EIPP::OrderInstall (17: File exists)
  • E:Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
  • E:Failed to write temporary StateFile /var/lib/apt/extended_states
  • W:Could not open file ‘/var/log/apt/term.log’ - OpenLog (13: Permission denied)
  • E:Sub-process /usr/bin/dpkg returned an error code (2)
  • W:Problem unlinking the file /var/cache/apt/pkgcache.bin - pkgDPkgPM::Go (13: Permission denied)

Handle get_archives and do_install in an easy wrapper.

Returns:
  • A Result: the Ok variant if transaction was successful, and Err if there was an issue.
Example:
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
use rust_apt::progress::{AptAcquireProgress, AptInstallProgress};

let cache = Cache::new();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AptAcquireProgress::new_box();
let mut install_progress = AptInstallProgress::new_box();

pkg.set(&Mark::Install).then_some(()).unwrap();
pkg.protect();
cache.resolve(true).unwrap();

// This needs root
// cache.commit(&mut acquire_progress, &mut install_progress).unwrap();

Clear any marked changes in the DepCache.

Returns an iterator of SourceURIs.

These are the files that apt update will fetch.

Returns an iterator of Packages that provide the virtual package.

NOTE: This function is ONLY designed to get the list of packages of a virtual package. It also expects that you’ll be installing the candidate version, and this likewise doesn’t return a specific version to install. You probably want to use Package::rev_provides_list instead.

Get a single package.

cache.get("apt") Returns a Package object for the native arch.

cache.get("apt:i386") Returns a Package object for the i386 arch

An iterator of packages in the cache.

The number of packages marked for installation.

The number of packages marked for removal.

The number of packages marked for keep.

The number of packages with broken dependencies in the cache.

The size of all packages to be downloaded.

The amount of space required for installing/removing the packages,“

i.e. the Installed-Size of all packages marked for installation“ minus the Installed-Size of all packages for removal.“

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.