Struct rust_apt::cache::Cache

source ·
pub struct Cache { /* private fields */ }
Expand description

The main struct for accessing any and all apt data.

Implementations§

source§

impl Cache

source

pub fn new<T: ToString>(deb_files: &[T]) -> Result<Cache, Exception>

Initialize the configuration system, open and return the cache. This is the entry point for all operations of this crate.

deb_files allows you to add local .deb files to the cache.

This function returns an Exception if any of the .deb files cannot be found.

Note that if you run Cache::commit or Cache::update, You will be required to make a new cache to perform any further changes

source

pub fn raw_pkgs(&self) -> Result<impl Iterator<Item = RawPackage>, Exception>

Internal Method for generating the package list.

source

pub fn depcache(&self) -> &DepCache

Get the DepCache

source

pub fn records(&self) -> &UniquePtr<Records>

Get the PkgRecords

source

pub fn pkg_manager(&self) -> &UniquePtr<PackageManager>

Get the PkgManager

source

pub fn resolver(&self) -> &UniquePtr<ProblemResolver>

Get the ProblemResolver

source

pub fn iter(&self) -> CacheIter<'_>

Iterate through the packages in a random order

source

pub fn packages( &self, sort: &PackageSort ) -> Result<impl Iterator<Item = Package<'_>>, Exception>

An iterator of packages in the cache.

source

pub fn update( self, progress: &mut Box<dyn AcquireProgress> ) -> Result<(), Exception>

Updates the package cache and returns a Result

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

use rust_apt::new_cache;
use rust_apt::raw::progress::{AcquireProgress, AptAcquireProgress};

let cache = new_cache!().unwrap();
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/
source

pub fn upgrade(&self, upgrade_type: &Upgrade) -> Result<(), Exception>

Mark all packages for upgrade

§Example:
use rust_apt::new_cache;
use rust_apt::cache::Upgrade;

let cache = new_cache!().unwrap();

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

pub fn resolve(&self, fix_broken: bool) -> Result<(), Exception>

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.

source

pub fn fix_broken(&self) -> bool

Autoinstall every broken package and run the problem resolver Returns false if the problem resolver fails.

§Example:
use rust_apt::new_cache;

let cache = new_cache!().unwrap();

cache.fix_broken();

for pkg in cache.get_changes(false).unwrap() {
    println!("Pkg Name: {}", pkg.name())
}
source

pub fn get_archives( &self, progress: &mut Box<dyn AcquireProgress> ) -> Result<(), Exception>

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::new_cache;
use rust_apt::raw::progress::{AptAcquireProgress};

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

pkg.mark_install(true, true);
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“
source

pub fn do_install( self, progress: &mut Box<dyn InstallProgress> ) -> Result<(), Exception>

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::new_cache;
use rust_apt::raw::progress::{AptAcquireProgress, AptInstallProgress};

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

pkg.mark_install(true, true);
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)
source

pub fn commit( self, progress: &mut Box<dyn AcquireProgress>, install_progress: &mut Box<dyn InstallProgress> ) -> Result<(), Box<dyn Error>>

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::new_cache;
use rust_apt::raw::progress::{AptAcquireProgress, AptInstallProgress};

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

pkg.mark_install(true, true);
pkg.protect();
cache.resolve(true).unwrap();

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

pub fn get(&self, name: &str) -> Option<Package<'_>>

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

source

pub fn get_changes( &self, sort_name: bool ) -> Result<impl Iterator<Item = Package<'_>>, Exception>

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

Methods from Deref<Target = Cache>§

source

pub fn update(&self, progress: &mut DynAcquireProgress) -> Result<(), Exception>

Update the package lists, handle errors and return a Result.

source

pub fn source_uris(&self) -> Vec<SourceURI>

Returns an iterator of SourceURIs.

These are the files that apt update will fetch.

source

pub fn create_depcache(&self) -> DepCache

source

pub fn create_records(&self) -> UniquePtr<Records>

source

pub fn priority(&self, version: &Version) -> i32

The priority of the Version as shown in apt policy.

source

pub fn find_index(&self, pkg_file: &mut PackageFile)

Lookup the IndexFile of the Package file

source

pub fn is_trusted(&self, pkg_file: &mut PackageFile) -> bool

Return true if the PackageFile is trusted.

source

pub fn unsafe_find_pkg(&self, name: String) -> Package

Return a package by name and optionally architecture.

source

pub fn begin(&self) -> Result<Package, Exception>

Return the pointer to the start of the PkgIterator.

source

pub fn find_pkg(&self, name: &str) -> Option<RawPackage>

Trait Implementations§

source§

impl Deref for Cache

Implementation to be able to call the raw cache methods from the high level struct

§

type Target = Cache

The resulting type after dereferencing.
source§

fn deref(&self) -> &Cache

Dereferences the value.
source§

impl<'a> IntoIterator for &'a Cache

§

type IntoIter = CacheIter<'a>

Which kind of iterator are we turning this into?
§

type Item = Package<'a>

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cache

§

impl !Send for Cache

§

impl !Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.