pub struct Cache { /* private fields */ }Expand description
The main struct for accessing any and all apt data.
Implementations§
source§impl Cache
impl Cache
sourcepub fn new<T: ToString>(deb_files: &[T]) -> Result<Cache, Exception>
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
sourcepub fn raw_pkgs(&self) -> Result<impl Iterator<Item = RawPackage>, Exception>
pub fn raw_pkgs(&self) -> Result<impl Iterator<Item = RawPackage>, Exception>
Internal Method for generating the package list.
sourcepub fn pkg_manager(&self) -> &UniquePtr<PackageManager>
pub fn pkg_manager(&self) -> &UniquePtr<PackageManager>
Get the PkgManager
sourcepub fn resolver(&self) -> &UniquePtr<ProblemResolver>
pub fn resolver(&self) -> &UniquePtr<ProblemResolver>
Get the ProblemResolver
sourcepub fn packages(
&self,
sort: &PackageSort
) -> Result<impl Iterator<Item = Package<'_>>, Exception>
pub fn packages( &self, sort: &PackageSort ) -> Result<impl Iterator<Item = Package<'_>>, Exception>
An iterator of packages in the cache.
sourcepub fn update(
self,
progress: &mut Box<dyn AcquireProgress>
) -> Result<(), Exception>
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/
sourcepub fn upgrade(&self, upgrade_type: &Upgrade) -> Result<(), Exception>
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();sourcepub fn resolve(&self, fix_broken: bool) -> Result<(), Exception>
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.
sourcepub fn fix_broken(&self) -> bool
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())
}sourcepub fn get_archives(
&self,
progress: &mut Box<dyn AcquireProgress>
) -> Result<(), Exception>
pub fn get_archives( &self, progress: &mut Box<dyn AcquireProgress> ) -> Result<(), Exception>
Fetch any archives needed to complete the transaction.
§Returns:
§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“
sourcepub fn do_install(
self,
progress: &mut Box<dyn InstallProgress>
) -> Result<(), Exception>
pub fn do_install( self, progress: &mut Box<dyn InstallProgress> ) -> Result<(), Exception>
Install, remove, and do any other actions requested by the cache.
§Returns:
§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)
sourcepub fn commit(
self,
progress: &mut Box<dyn AcquireProgress>,
install_progress: &mut Box<dyn InstallProgress>
) -> Result<(), Box<dyn Error>>
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:
§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();Methods from Deref<Target = Cache>§
sourcepub fn update(&self, progress: &mut DynAcquireProgress) -> Result<(), Exception>
pub fn update(&self, progress: &mut DynAcquireProgress) -> Result<(), Exception>
Update the package lists, handle errors and return a Result.
sourcepub fn source_uris(&self) -> Vec<SourceURI>
pub fn source_uris(&self) -> Vec<SourceURI>
Returns an iterator of SourceURIs.
These are the files that apt update will fetch.
pub fn create_depcache(&self) -> DepCache
pub fn create_records(&self) -> UniquePtr<Records>
sourcepub fn priority(&self, version: &Version) -> i32
pub fn priority(&self, version: &Version) -> i32
The priority of the Version as shown in apt policy.
sourcepub fn find_index(&self, pkg_file: &mut PackageFile)
pub fn find_index(&self, pkg_file: &mut PackageFile)
Lookup the IndexFile of the Package file
sourcepub fn is_trusted(&self, pkg_file: &mut PackageFile) -> bool
pub fn is_trusted(&self, pkg_file: &mut PackageFile) -> bool
Return true if the PackageFile is trusted.
sourcepub fn unsafe_find_pkg(&self, name: String) -> Package
pub fn unsafe_find_pkg(&self, name: String) -> Package
Return a package by name and optionally architecture.
sourcepub fn begin(&self) -> Result<Package, Exception>
pub fn begin(&self) -> Result<Package, Exception>
Return the pointer to the start of the PkgIterator.