Struct 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: AsRef<str>>(local_files: &[T]) -> Result<Cache, AptErrors>

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

local_files allows you to temporarily add local files to the cache, as long as they are one of the following:

  • *.deb or *.ddeb files
  • Packages and Sources files from apt repositories. These files can be compressed.
  • *.dsc or *.changes files
  • A valid directory containing the file ./debian/control

This function returns an AptErrors if any of the files cannot be found or are invalid.

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) -> impl Iterator<Item = UniquePtr<PkgIterator>>

Internal Method for generating the package list.

Source

pub fn depcache(&self) -> &DepCache

Get the DepCache

Source

pub fn records(&self) -> &PackageRecords

Get the PkgRecords

Source

pub fn pkg_manager(&self) -> &PackageManager

Get the PkgManager

Source

pub fn resolver(&self) -> &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) -> impl Iterator<Item = Package<'_>>

An iterator of packages in the cache.

Source

pub fn update(self, progress: &mut AcquireProgress<'_>) -> Result<(), AptErrors>

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::progress::AcquireProgress;

let cache = new_cache!().unwrap();
let mut progress = AcquireProgress::apt();
if let Err(e) = cache.update(&mut progress) {
    for error in e.iter() {
        if error.is_error {
            println!("Error: {}", error.msg);
        } else {
            println!("Warning: {}", error.msg);
        }
    }
}
§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<(), AptErrors>

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<(), AptErrors>

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::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) {
    println!("Pkg Name: {}", pkg.name())
}
Source

pub fn get_archives( &self, progress: &mut 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::progress::AcquireProgress;

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

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 InstallProgress<'_>, ) -> Result<(), AptErrors>

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::progress::{AcquireProgress, InstallProgress};

let cache = new_cache!().unwrap();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AcquireProgress::apt();
let mut install_progress = InstallProgress::apt();

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 AcquireProgress<'_>, install_progress: &mut InstallProgress<'_>, ) -> Result<(), AptErrors>

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::progress::{AcquireProgress, InstallProgress};

let cache = new_cache!().unwrap();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AcquireProgress::apt();
let mut install_progress = InstallProgress::apt();

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) -> impl Iterator<Item = Package<'_>>

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 = PkgCacheFile>§

Source

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

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

Source

pub fn get_indexes(&self, fetcher: &PkgAcquire) -> bool

Loads the index files into PkgAcquire.

Used to get to source list uris.

It’s not clear if this returning a bool is useful.

Source

pub unsafe fn create_depcache(&self) -> UniquePtr<PkgDepCache>

Return a pointer to PkgDepcache.

§Safety

The returned UniquePtr cannot outlive the cache.

Source

pub unsafe fn create_records(&self) -> UniquePtr<PkgRecords>

Return a pointer to PkgRecords.

§Safety

The returned UniquePtr cannot outlive the cache.

Source

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

The priority of the Version as shown in apt policy.

Source

pub unsafe fn find_index(&self, file: &PkgFileIterator) -> UniquePtr<IndexFile>

Lookup the IndexFile of the Package file

§Safety

The IndexFile can not outlive PkgCacheFile.

The returned UniquePtr cannot outlive the cache.

Source

pub unsafe fn find_pkg(&self, name: &str) -> UniquePtr<PkgIterator>

Return a package by name and optionally architecture.

§Safety

If the Internal Pkg Pointer is NULL, operations can segfault. You should call make_safe() asap to convert it to an Option.

The returned UniquePtr cannot outlive the cache.

Source

pub unsafe fn begin(&self) -> UniquePtr<PkgIterator>

Return the pointer to the start of the PkgIterator.

§Safety

If the Internal Pkg Pointer is NULL, operations can segfault. You should call raw_iter() asap.

The returned UniquePtr cannot outlive the cache.

Trait Implementations§

Source§

impl Deref for Cache

Source§

type Target = PkgCacheFile

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl !Freeze for Cache

§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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

Source§

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.